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() functionintprintf(constchar*format, ...);intmain(){printf("Hello World");return0;}chevron_rightfilter_noneOutput: 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++ compilerextern"C"{intprintf(constchar*format, ...);}intmain(){printf("Hello World");return0;}chevron_rightfilter_noneOutput: 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 contribute@geeksforgeeks.org. 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.
Recommended Posts:
- Comment in header file name?
- How to write your own header file in C?
- Difference between Header file and Library
- clocale header file in C++
- time.h header file in C with Examples
- <complex.h> header file in C with Examples
- Print substring of a given string without using any string function and loop in C
- Write a C program to print "GfG" repeatedly without using loop, recursion and any control structure?
- How to print range of basic data types without any library function and constant in C?
- C program to print a string without any quote (singe or double) in the program
- To find sum of two numbers without using any operator
- 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)
- What’s difference between header files "stdio.h" and "stdlib.h" ?
- random header in C++ | Set 3 (Distributions)
- Exception header in C++ with examples
- dos.h header in C with examples

