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”.
 

 
 
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Loading...

Thanks for reading.

Please use our online compiler to post code in comments. To contribute, get in touch with us.
Like us? Please spread the word and help us grow. Happy coding 🙂
 



Leave a Reply

avatar
  Subscribe  
Notify of