Lesson 26 of 50
cPreprocessor Directives
9 mins
Course progress52%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 26 of 50
c9 mins
Keep these ideas in mind as you work through the lesson.
The preprocessor runs before compilation and handles macros, file inclusion, and conditional compilation.
#define PI 3.14159
#define SQUARE(x) ((x)*(x))
#if defined(_WIN32)
#define PLATFORM "Windows"
#else
#define PLATFORM "Other"
#endif
Common directives:
#include "file.h" – include header.#define / #undef – macros.#if, #ifdef, #ifndef, #else, #elif, #endif – conditional compilation.#pragma – implementation‑specific instructions.Macros are textual replacements; they are not type‑checked. Use static inline functions for safer alternatives when possible.