Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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.

Attention reader! All those who say programming isn't for kids, just haven't met the right mentors yet. Join the  Demo Class for First Step to Coding Coursespecifically designed for students of class 8 to 12. 

The students will get to learn more about the world of programming in these free classes which will definitely help them in making a wise career choice in the future.

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

My Personal Notes arrow_drop_up

Start Your Coding Journey Now!