Open In App

Print “Hello World” with empty or blank main in C++

Write a program in C++ that prints “Hello World”, it has a main function and body of main function is empty.

Following are three different solutions.








// C++ program to print something with empty main()
#include <iostream>
using namespace std;
 
class A {
public:
    A() // Constructor
    {
        cout << "Hello World";
    }
};
 
A obj; // Create Object of class A
 
int main()
{
    // Blank
}




// C++ program to print something with empty main()
#include <iostream>
  
int fun()
{
    std::cout << "Hello World";
    return 1;
}
  
int x = fun(); // global variable
  
int main() {}

Related article: How to print “GeeksforGeeks” with empty main() in C, C++ and Java?


Article Tags :
C++