What is file inclusion directive or #include directive in c programming language?

Answer:

Syntax:

#include

or

#include “filename.h”

 

This directive treats has included in the current file i.e. in current file also contain data of the file which has included by #include directive.

e.g.

First create a file of file name cube.h which contains:

 

int cube ( int a)

{

int b;

b=(a)*(a)*(a);

return b;

}

 

Now create any another c file let math.c which contains:

 

#include “cube.h”

void main()

{

int p=5,q;

q=cube(p);

printf(“%d”,q);

}

Output: 125

Explanation:

When we write #include “cube.h” the compiler includes contain of file cube.h i.e. cube function in the math.c file. So we can use the function which has defined in cube.h .We can see the intermediate file of math.c:

  

#include: Search the file only include directory (c:\tc\include)

#include “filename.h”: Search the file include directory as well as current working directory.

Note: In the above question if you will save the file cube.h at c:\tc\include directory then you can write in math.c: