

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print “Hello World” with empty or blank main in C++
In this problem we will see how to print “Hello World” into the console, but we cannot write anything into the main function.
This problem can be solved in two different ways. In the first approach we will create a global variable, then we will store the returned value of printf() function into that variable. When printf() is executed, then it will be printed. See the code for better understanding.
Example
#include<iostream> using namespace std; int a = printf("Hello World"); int main() { }
Output
Hello World
In the next approach we will create a class, and print the line using the constructor of that class. Then create an object of that class at the global section. So when the object is created, it will call the constructor automatically, and the line will be printed.
Example
#include<iostream> using namespace std; class my_class { public: my_class() { cout << "Hello World"; } }; my_class my_obj; int main() { }
Output
Hello World
- Related Questions & Answers
- Python Program to Print Hello world
- Print Hello World without semicolon in C++
- Beginning C# programming with Hello World
- Beginning Java programming with Hello World
- How to print "Hello World!" using Python?
- Hello World using Perl.
- Beginning Java programming with Hello World Example
- Hello World Program in Java
- Hello World in Dart Programming
- Creating Java Hello World Program
- Display hello world using React.js
- First Hello World project in Arduino
- Print “Hello World” in C/C++ without using header files
- Print “Hello World” without using any header file in C
- C Program to print “Hello World!” without using a semicolon
Advertisements