Convert C/C++ program to Preprocessor coden

Here we will see how to generate the preprocessed or preprocessor code from the source code of a C or C++ program.

To see the preprocessed code using g++ compiler, we have to use the ‘-E’ option with the g++.

Preprocessor includes all of the # directives in the code, and also expands the MACRO function.


g++ -E program.cpp


#define PI 3.1415
int main() {
   float a = PI, r = 5;
   float c = a * r * r;
   return 0;


$ g++ -E test_prog.cpp
int main() {
   float a = 3.1415, r = 5;
   float c = a * r * r;
   return 0;