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

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

 

Method 1:

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

 
Please note that we can also use C++ class instead of using struct in similar way as shown below –
 

 


 

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