Lesson 26 of 50 · c
Preprocessor Directives
Duration: 9 mins
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.