Skip to content
Related Articles

Related Articles

C/C++ program to print Hello World without using main() and semicolon
  • Difficulty Level : Easy
  • Last Updated : 25 Nov, 2019

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

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.

My Personal Notes arrow_drop_up
Recommended Articles
Page :