Open In App

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

Improve
Improve
Like Article
Like
Save
Share
Report

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




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


C++




// 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") {
    }
}


Output:

Hello World

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

Time Complexity: O(1)
Auxiliary Space: O(1)


Last Updated : 21 Jun, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads