Print "Hello World" with empty or blank main in C++ Last Updated : 14 Jun, 2022 Comments Improve Suggest changes 3 Likes Like Report 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. We can create a global variable and assign it return value of printf() that prints "Hello World" CPP // C++ program to print something with empty main() #include <bits/stdc++.h> int x = printf("Hello World"); int main() { // Blank } We can use Constructor in C++. In the below program, we create an object of class 'A' outer of the main Function so object declaration time it will be call to constructor so that it will be print "Hello World". CPP // 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 } We can initialize a global variable with return type of function that prints “Hello World”. C++ // 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? Create Quiz Comment D Devanshu Agarwal 3 Improve D Devanshu Agarwal 3 Improve Article Tags : Misc C++ cpp-puzzle Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like