Master the C preprocessor!
- Preprocessor directives
- Macros and macro functions
- Conditional compilation
- Header guards
- Common preprocessor tricks
#include <stdio.h>
#define PI 3.14159
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define SQUARE(x) ((x) * (x))
int main() {
printf("PI = %f\n", PI);
printf("MAX(5, 10) = %d\n", MAX(5, 10));
printf("SQUARE(4) = %d\n", SQUARE(4));
return 0;
}#ifndef MY_HEADER_H
#define MY_HEADER_H
// Header content here
#endif#define DEBUG
#ifdef DEBUG
printf("Debug mode enabled\n");
#endif
#if defined(WINDOWS)
// Windows code
#elif defined(LINUX)
// Linux code
#else
// Other OS code
#endifModule 11: Data Structures Fundamentals
Each source file has a companion markdown file with detailed explanations:
| File | Description |
|---|---|
advanced_preprocessor.c 📄 |
Advanced Preprocessor demonstration |
conditional_compilation.c 📄 |
Conditional Compilation demonstration |
preprocessor_demo.c 📄 |
Preprocessor Demo demonstration |
- 📄 = Detailed explanation available
- 🐛 = Contains deliberate bugs for learning