Can we execute a program without entering into main( ) function?

Here is a program which ends before execution of main( ) function starts but still manages to get the output.

Basically all global objects are created before entering into main(); So you can write any code into the constructor of objects, which will be called whenever object is created.

class A

{

public :

A( )

{

cout << “In A” ;

exit( 1 ) ;

}

} ;

main( )

{

cout << “not reached” ;

}

A a ;

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>