|
|
|
|
![]() ![]() |
Jun 4 2007, 06:10 PM
Post
#1
|
|
|
Newbie [Level 3] ![]() ![]() ![]() Group: Members Posts: 46 Joined: 4-June 07 Member No.: 44,157 |
Hi guys can u make a program to write hello on screen without writing anything in main()
CODE #include<stdio.h> #include<iostream.h> class hello { int a; public: hello(){cout<<"hello";}; }magic; void main() { } Can u guess how it worked since we are creating an global object of hello class it gets executed at the first and its constructor in which we have written hello that statement gets executed as a result hello gets printed on the screen and then the main comes in to existence cool na ,its the magic of oops This post has been edited by sourabhj: Jun 5 2007, 04:02 AM |
|
|
|
Jun 5 2007, 05:36 AM
Post
#2
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 399 Joined: 14-November 04 From: Elysium Member No.: 2,280 |
Clever coding. Of course, it's not the most efficient thing to go about creating global declarations in order to execute code, but... nice.
Two (technical) questions: I) why'd you include stdio.h? I'm not seeing any c functions. Just adding kilobytes to the program size. II) why is everyone assuming a using std statement here? It doesn't make sense to do it in a public forum where some people *cough*me*cough* use ANSI strict styles for coding. It can also confuse newbies to C++. ~just a syntax argument. |
|
|
|
Jun 5 2007, 05:54 AM
Post
#3
|
|
|
Newbie [Level 3] ![]() ![]() ![]() Group: Members Posts: 46 Joined: 4-June 07 Member No.: 44,157 |
Clever coding. Of course, it's not the most efficient thing to go about creating global declarations in order to execute code, but... nice. Two (technical) questions: I) why'd you include stdio.h? I'm not seeing any c functions. Just adding kilobytes to the program size. II) why is everyone assuming a using std statement here? It doesn't make sense to do it in a public forum where some people *cough*me*cough* use ANSI strict styles for coding. It can also confuse newbies to C++. ~just a syntax argument. Yes u are right there is no use of stdio.h,actually its a like template ,i have been using, since std functions are sometimes needed and its time consuming and pain to write include statement in turboc 3.0 so i made a format which i copy paste in program then start coding. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 8th October 2008 - 07:00 AM |