Open In App

Print “Hello World” in C/C++ without using any header file

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:-

See this to know more about all phases of compilation of C program.



This blog is contributed by Shubham Bansal.

Article Tags :