Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> A C++ Program Print Hello With Nothing Written In Main() Method, Its the magic of oops
sourabhj
post 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() ohmy.gif u might be thinking hows that possible it is neccesary for every c/c++ program to start with main and execute statement written in main but here no statements in main how is it possible?,dont worry it is possible ill show u how:

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

cool.gifcool.gif

This post has been edited by sourabhj: Jun 5 2007, 04:02 AM
Go to the top of the page
 
+Quote Post
osknockout
post 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. biggrin.gif

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.
Go to the top of the page
 
+Quote Post
sourabhj
post Jun 5 2007, 05:54 AM
Post #3


Newbie [Level 3]
***

Group: Members
Posts: 46
Joined: 4-June 07
Member No.: 44,157



QUOTE(osknockout @ Jun 5 2007, 11:06 AM) *
Clever coding. Of course, it's not the most efficient thing to go about creating global declarations in order to execute code, but... nice. biggrin.gif

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.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Stop A Program Excecution(4)
  2. Program Flow(2)
  3. Timeouting Program(2)
  4. Crazy Looking C Program(19)
  5. C++(15)
  6. Run A Program From Another One(4)
  7. Program From Mekka 97 4k(2)
  8. Need Debugging Help For A Simple Program(3)
  9. Need Help With C Program To Test If A Number Is Prime(12)
  10. Executing An Exe From Within A Program!(7)
  11. My First C++ Program(6)
  12. Source Code For Paint Like Program Under Dos In C(2)
  13. Program Lang I Know(2)
  14. Centering The Text In A Simple C++ Program?(8)
  15. Buffer Overflow In Action Tutorial(0)
  1. C Or C++ Easy Programming Generator(6)
  2. A Crazy Program In C(13)
  3. How To Run A Process Through Your Program (c#)(0)
  4. Any Program Ideas?!(5)
  5. If/else Demo Program Bug(4)


 



- Lo-Fi Version Time is now: 8th October 2008 - 07:00 AM