C - Preprocessor

The preprocessor runs before compilation and handles directives like #include, #define, and conditional compilation.

Learning Objectives

  • Use #include and #define appropriately.
  • Guard headers and use conditional compilation.

Examples

#include <stdio.h>
#define PI 3.14159

int main(void) {
  printf("%.2f\n", PI);
}

Header guards

#ifndef MY_HEADER_H
#define MY_HEADER_H
// declarations
#endif

Conditional compilation

#if DEBUG
  printf("debugging...\n");
#endif