Print “Hello World” with empty main function | 3 methods

Write a program to print “Hello World” without writing anything inside main() function i.e. main() function should be empty.


 

Method 1:

Using cout/printf() inside constructor of struct/class and creating its object outside main().
 

 

Note – We can also use C++ class instead of using struct in similar way.
 


 

Method 2:

Initialize a global variable with return type of printf() after printing “Hello World”
 

 


 

Method 3:

Initialize a global variable with return type of a function that prints “Hello World”.
 

 
Thanks for reading.




Please use ideone or C++ Shell or any other online compiler link to post code in comments.
Like us? Please spread the word and help us grow. Happy coding 🙂
 





Leave a Reply

Notify of
avatar
wpDiscuz