Sunday, 21 January 2018

Significance of header file



To understand significance of header file. I would like to ask you a question. Why do we choose high level language to develop software instead of low level language?

Answer is we choose high level language like C language  to develop software. Because there are lots of things that can be achieved by only calling some function provided by related language compiler. One the other hand in low level language every things of programming is manually done by programmer. For example if you want to generate output on screen using assembly language you will have to set many register value which is very complicated. Whereas in C language you will have to use inbuilt function printf.


That’s the main reason of using high level language because a programmer energy consume to implement business logic not the system level task like input or output and many more.

C language provides a reach variety of inbuilt function for lots of operations. All inbuilt function in C language bundle in header file. A programmer needs to include just a header file reference and he/she will be able to call all function inside of a header file.

Header file start with # symbol followed by includes <header_file_name>. Extension of header file is .H.

Given syntax searches for a file named header_file_name in a standard list of system directories. You can prepend directories to this list with the -I option while compiling your source code.

Including a header file is equal to copying the content of the header file but we do not do it because it will be error-prone and it is not a good idea to copy the content of a header file in the source files, especially if we have multiple source files in a program.

#include<stdio.h>
#include<conio.h>
void main()
{

    
     clrscr();
     printf("\nHello C \n");
    
     getch();
}


In given program printf function is in stdio.h and clrscr and getch is part of conio.h.

So you can see you will have to visit the function list of a header file. Which covers a specific operation. For example if you want to process string then you can use string.h.

So header file save our time and provides a predefined and tested library function.


  

No comments:

Post a Comment