What is a header file in C?
a) A file that contains function declarations and macros
b) A file that contains the main function
c) A file that is used for memory management
d) A file that is used to store global variables
Answer:
a) A file that contains function declarations and macros
Explanation:
A header file in C is a file with a .h
extension that contains function declarations, macros, constants, and type definitions. These files are included in C programs using the #include
directive, allowing for the reuse of code across multiple source files. Standard header files like stdio.h
and stdlib.h
provide declarations for functions like printf()
and malloc()
.
Using header files promotes modularity and helps organize code by separating the implementation of functions and data structures from their declarations. This makes programs easier to understand, maintain, and extend.