Example code for __cplusplus macro in c:
what is __cplusplus?
What is the output of below c program?
using namespace std;
If you run this in c, output is 'c'
If you run this in c++, output is 'c'
option 1 and option 2 both are right
option 1 is right, and 2 is reversed.
This is an example of conditional compilation, where for c compilers it prints "c" as output. And for c++ systems it prints "c++" as #ifdef __cplusplus is true for c++ compilers. This is how to write a program which executes different statements based on if it is c or c++. (conditional compilation)
Back To Top