What is #include

# is called Pre-processor directive.

What is Pre-processor ? 🙄

Pre-processor is a program that performs before the compilation. 
 Pre-processor only notices # started statements.
Include is a "pre-processor" command.

What does include do?🙄

The work of "include" is to include the content of an external file in our program.
It can be written in two ways
  1. #include<file_name>
  2. #include”file_name”
There is a minor difference between these two.

Let us understand the topic in detail

let us take an example,
  this is our source code

#include<stdio.h>
int main()
{
printf (“hello world”);
return 0;
}

  • Now pre-processor will only focus on #include<stdio.h> as # symbol is present. 
  • Note that stdio.h is an external header file.
  • Now our task is to create another file that includes the contents of our file and external file.


Before compilation😁


what-hash-include-c
The lines of “our file” and “External file” are included in “file for the compilation”
 
After this process, the file for compilation is compiled.

Difference between 

#include<file_name>

#include”file_name”

  • When the file name is already included in the C library then we write #include<file_name>
  • Eg:: #include<stdio.h>
  • Stdio.h is already included in the C library which has a   specific path, and which is known by the C pre-processor.
  • The external file which we include doesn't need to be a header file, we can include a source file also.
  • Suppose we have included an external file that does not belong to the C library and whose path is not known by the C pre-processor.
  • In such a case, we write #include”file_name”
  • Eg:: #include”c:\demoprog\list.h”
  • We have to write the entire path of the file.