C/C++ program to print Hello World without using main() and semicolon

The task is to write a program to print Hello World without using main() and semicolon.

As we already know how to print Hello World without the use of a semicolon. Now for writing without main() method, we will need a Macro.

C

filter_none

edit
close

play_arrow

link
brightness_4
code

// C program to print Hello World
// without using main() and semicolon
  
#include <stdio.h>
  
#define x main
  
void x()
{
    if (printf("Hello World")) {
    }
}

chevron_right


C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to print Hello World
// without using main() and semicolon
  
#include <bits/stdc++.h>
using namespace std;
  
#define x main
  
void x()
{
    if (cout << "Hello World") {
    }
}

chevron_right


Output:

Hello World

C/C++ program to print Hello World without using main() and semicolon



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.