The Wayback Machine - https://web.archive.org/web/20240118172509/https://www.geeksforgeeks.org/c-c-program-to-print-hello-world-without-using-main-and-semicolon/
Open In App
Related Articles

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

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
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)

Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 21 Jun, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads