Header Files in C/C++

A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that comes with your compiler.

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.

They are most often used to include external variable declarations, macro definitions, type definitions, and function declarations. Groups of logically related functions are commonly declared together in a header file, such as the C library input and output functions listed in the stdio.h header file.

There are of 2 types of header file:

  1. Pre-existing header files: Files which are already available in C/C++ compiler we just need to import them.

  2. User-defined header files: These files are defined by the user and can be imported using #include.

Header Files in C/C++

Below are some inbuilt header files in C/C++:

1. <assert.h>

The assert.h header file provide macro called assert which is used to verify assumptions make by the program and print diagnostic message. If the assumption you make about the code is correct it continues without disruption. f the assumption isn't correct it prints a diagnostic message.

Function list

  1. void assert(int expression) - This is actually a macro and not a function, which can be used to add diagnostics in your C program.

2. <complex.h>

The Complex.h header file is used for complex number operations and manipulations. cmplx() function creates complex number objects by taking real part and imaginary parts as parameters. This function returns the object of complex numbers.

3. <ctype.h>

The ctype.h header file of the C Standard Library declares several functions that are useful for testing and mapping characters. All the functions accepts int as a parameter, whose value must be EOF or representable as an unsigned char. All the functions return non-zero (true) if the argument c satisfies the condition described, and zero(false) if not.