Learn the difference between C++ preprocessor and compiler in the compilation process. Understand how preprocessor directives (/#include, /#define) work, how the compiler checks syntax and generates machine code, and see the complete compilation flow with examples. Perfect for C++ beginners.
# (like #include, #define, #ifdef) before actual compilation begins.Key Points:
#.Examples:
#include <iostream> // includes the iostream header file
#define PI 3.14159 // defines a constant
Key Points:
program.cpp generates program.exe (on Windows) or a.out (on Linux/Mac).| Feature | Preprocessor | Compiler |
|---|---|---|
| When it runs | Before compilation | After preprocessing |
| Purpose | Prepares source code | Converts code to machine code |
| Syntax checking | No | Yes |
| Handles | Directives (#include, #define) |
C++ code |
| Output | Modified source code | Executable/machine code |
💡 Example Flow in C++ Compilation:
#include files, #define constants handled)