C program without header file?

This question is generally asked in interviews to confuse the candidate and also to test the knowledge of the student in C programming.

So, in short, the answer is yes. We can compile C program without header file.
But how?

Firstly all the function that we generally use like printf, scanf, etc are declared and defined in the header file.

So, in a C program header file is used to import some predefined functions.
So, in case you don’t want to use a header file?

You can simply define the function you want to use in your program and compile it.

For Example:

//Declare the printf() function
  int printf(const char *format, ...);
  int main()
  printf( "Hello StudyMite !" );
  return 0;

Output :

Hello StudyMite !

In the above code, we first have to declare printf in our program(as we are not including header file). After that we can use it in our main function.


CopyRight © 2019

CopyRight © 2019