C PROGRAMMING
LANGUAGE
Complete Reference Guide
Preprocessor Directives & Standard Header Files
■■■■■■■■■■■■■■■■■■■■■
All Directives • All Standard Headers • Syntax • Examples • Best Practices
A Comprehensive Technical Reference
, Table of Contents
Chapter 1 Introduction to the C Preprocessor 3
Chapter 2 #include — File Inclusion Directives 4
Chapter 3 #define — Macro Definition Directives 5
Chapter 4 Conditional Compilation Directives 7
Chapter 5 #pragma and Miscellaneous Directives 9
Chapter 6 Predefined Macros 10
Chapter 7 Standard C Header Files — Complete Reference 11
Chapter 8 Best Practices and Common Pitfalls 20
C Programming Language — Preprocessor Directives & Header Files Reference Page 2
, Introduction to the C Preprocessor
1 Understanding how the preprocessor works before compilation
What is the C Preprocessor?
The C Preprocessor (CPP) is a macro processor that automatically processes your source code
before the actual compilation begins. It is the first step in the C compilation pipeline. The
preprocessor handles directives that begin with the '#' symbol and performs text substitution, file
inclusion, and conditional compilation.
The compilation pipeline in C works as follows:
• Preprocessing → Source code + header files → Expanded source
• Compilation → Expanded source → Assembly code
• Assembly → Assembly code → Object code
• Linking → Object code + libraries → Executable
C Language
// Example: What the preprocessor does
#define MAX 100 // MAX becomes literal 100 everywhere
#include <stdio.h> // Inserts entire stdio.h file here
int main() {
printf("Max = %d\n", MAX); // becomes printf("Max = %d\n", 100)
return 0;
}
Categories of Preprocessor Directives
All C preprocessor directives fall into these main categories:
Directive Syntax / Example Purpose
#include #include or "file" Include a header file into the source
#define #define NAME value Define a macro or constant
#undef #undef NAME Undefine a previously defined macro
#if / #ifdef #ifdef NAME ... #endif Conditional compilation
#ifndef #ifndef NAME ... #endif Conditional compilation (not defined)
#elif / #else #elif COND ... #else ... Alternative branches in conditionals
#endif #endif End of a conditional block
#pragma #pragma once / #pragma pack Compiler-specific instructions
C Programming Language — Preprocessor Directives & Header Files Reference Page 3
LANGUAGE
Complete Reference Guide
Preprocessor Directives & Standard Header Files
■■■■■■■■■■■■■■■■■■■■■
All Directives • All Standard Headers • Syntax • Examples • Best Practices
A Comprehensive Technical Reference
, Table of Contents
Chapter 1 Introduction to the C Preprocessor 3
Chapter 2 #include — File Inclusion Directives 4
Chapter 3 #define — Macro Definition Directives 5
Chapter 4 Conditional Compilation Directives 7
Chapter 5 #pragma and Miscellaneous Directives 9
Chapter 6 Predefined Macros 10
Chapter 7 Standard C Header Files — Complete Reference 11
Chapter 8 Best Practices and Common Pitfalls 20
C Programming Language — Preprocessor Directives & Header Files Reference Page 2
, Introduction to the C Preprocessor
1 Understanding how the preprocessor works before compilation
What is the C Preprocessor?
The C Preprocessor (CPP) is a macro processor that automatically processes your source code
before the actual compilation begins. It is the first step in the C compilation pipeline. The
preprocessor handles directives that begin with the '#' symbol and performs text substitution, file
inclusion, and conditional compilation.
The compilation pipeline in C works as follows:
• Preprocessing → Source code + header files → Expanded source
• Compilation → Expanded source → Assembly code
• Assembly → Assembly code → Object code
• Linking → Object code + libraries → Executable
C Language
// Example: What the preprocessor does
#define MAX 100 // MAX becomes literal 100 everywhere
#include <stdio.h> // Inserts entire stdio.h file here
int main() {
printf("Max = %d\n", MAX); // becomes printf("Max = %d\n", 100)
return 0;
}
Categories of Preprocessor Directives
All C preprocessor directives fall into these main categories:
Directive Syntax / Example Purpose
#include #include or "file" Include a header file into the source
#define #define NAME value Define a macro or constant
#undef #undef NAME Undefine a previously defined macro
#if / #ifdef #ifdef NAME ... #endif Conditional compilation
#ifndef #ifndef NAME ... #endif Conditional compilation (not defined)
#elif / #else #elif COND ... #else ... Alternative branches in conditionals
#endif #endif End of a conditional block
#pragma #pragma once / #pragma pack Compiler-specific instructions
C Programming Language — Preprocessor Directives & Header Files Reference Page 3