Loading lessons...
The Preprocessor
The Preprocessor
Before compiling, a preprocessor scans the file. It handles # directives.
Includes
#include <stdio.h> // standard library
#include "myfile.h" // your own header
Macros (defines)
#define PI 3.14159
Everywhere PI appears, the text 3.14159 replaces it before compile.
Macro with an argument
#define MAX(a, b) ((a) > (b) ? (a) : (b))
Why macros?
Useful for constants and quick helpers, but macros are error-prone. Prefer const when possible.
TL;DR
- Runs before compilation.
- Handles #include and #define.
- Macros are simple text swaps.
- Prefer constants over overkill macros.