Header files in C contain declarations of functions and macros. They allow you to reuse code and organize functions logically.
They typically have a .h extension and are included using the #include directive.
#include <stdio.h>, #include <math.h>#include "myheader.h"
Preprocessor directives are commands that begin with # and are processed before the compilation starts.
They are used to include files, define macros, and conditionally compile code.
#include – Includes a header file.#define – Defines a macro or constant.#undef – Undefines a macro.#ifdef / #ifndef – Conditional compilation if a macro is defined or not defined.#if / #else / #elif / #endif – Multi-branch conditional compilation.#include <stdio.h>
#define PI 3.14159
int main() {
printf("Value of PI: %.2f\n", PI);
return 0;
}
Explanation:
#include <stdio.h> tells the compiler to include standard input-output functions.
#define PI 3.14159 defines a macro constant named PI.