Skip to content
doubtly

1 answer

Header files give the compiler the declarations (function prototypes, macros, constants and data types) of library functions, so that we can use those functions correctly in our program.

For example, in C:

#include <stdio.h>
#include <math.h>

int main(void) {
    printf("%f\n", sqrt(16.0));
    return 0;
}

Here stdio.h declares printf() and math.h declares sqrt().

Significance:

  • Declarations for the compiler: the compiler learns the name, return type and parameters of each function, so it can check that calls are correct.
  • Reusability: we use ready-made, tested library functions instead of writing them ourselves.
  • Macros and constants: header files define things like NULL, EOF and INT_MAX.
  • Modular programs: we can write our own header files (e.g. #include "myfile.h") to share declarations among several source files.

The #include directive is handled by the preprocessor, which copies the contents of the header file into the program before compilation.

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.