Write a C/C++ program that prints Hello World without including any header file.
Conceptually it’s seems impractical to write a C/C++ program that print Hello World without using a header file of “stdio.h”. Since the declaration of printf() function contains in the “stdio.h” header file.
But we can easily achieve this by taking the advantage of C pre-processor directives. The fact is at the time of compiling a program, the first phase of C preprocessing expands all header files into a single file and after that compiler itself compiles the expanded file. Therefore we just need to extract the declaration of printf() function from header file and use it in our main program like that:-
- C language: Just declare the printf() function taken from “stdio.h” header file.
//Declare the printf() function
Output: Hello World
- C++ language: We can’t directly put the declaration of printf() function as in previous case due to the problem of Name mangling in C++. See this to know more about Name mangling. Therefore we just need to declare the printf() inside extern keyword like that:-
//Declare the printf() function inside
//extern "C" for C++ compiler
Output: Hello World
See this to know more about all phases of compilation of C program.
This blog is contributed by Shubham Bansal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- clocale header file in C++
- Write a C program to print "GfG" repeatedly without using loop, recursion and any control structure?
- C program to print a string without any quote (singe or double) in the program
- accumulate() and partial_sum() in C++ STL : numeric header
- numeric header in C++ STL | Set 2 (adjacent_difference(), inner_product() and iota())
- Namespace in C++ | Set 3 (Accessing, creating header, nesting and aliasing)
- random header in C++ | Set 1(Generators)
- random header | Set 2 (Distributions)
- random header in C++ | Set 3 (Distributions)
- Exception header in C++ with examples
- Header files in C/C++ with Examples
- Implementing ternary operator without any conditional statement
- Programming puzzle (Assign value without any control statement)
- How will you print numbers from 1 to 100 without using loop?
- Write a C program to print "Geeks for Geeks" without using a semicolon
- Print "Even" or "Odd" without using conditional statement
- Print individual digits as words without using if or switch
- C Program to print numbers from 1 to N without using semicolon?
- How to print a semicolon(;) without using semicolon in C/C++?
- How to print a number 100 times without using loop and recursion in C?