Challenge - 5 Problems
Conditional Compilation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of conditional compilation with defined macro
What is the output of this C program when compiled and run?
C
#include <stdio.h> #define DEBUG int main() { #ifdef DEBUG printf("Debug mode\n"); #else printf("Release mode\n"); #endif return 0; }
Attempts:
2 left
💡 Hint
Look at the #ifdef directive and the defined macro.
✗ Incorrect
Since DEBUG is defined, the #ifdef DEBUG block runs, printing "Debug mode".
❓ Predict Output
intermediate2:00remaining
Output when macro is not defined
What will this program print when compiled and run?
C
#include <stdio.h> int main() { #ifndef RELEASE printf("Debug build\n"); #else printf("Release build\n"); #endif return 0; }
Attempts:
2 left
💡 Hint
Check if RELEASE is defined or not.
✗ Incorrect
RELEASE is not defined, so #ifndef RELEASE is true and prints "Debug build".
❓ Predict Output
advanced2:00remaining
Output with nested conditional compilation
What is the output of this program?
C
#include <stdio.h> #define FEATURE_X int main() { #ifdef FEATURE_X #ifdef FEATURE_Y printf("Feature X and Y enabled\n"); #else printf("Only Feature X enabled\n"); #endif #else printf("No features enabled\n"); #endif return 0; }
Attempts:
2 left
💡 Hint
Check which macros are defined.
✗ Incorrect
FEATURE_X is defined but FEATURE_Y is not, so it prints "Only Feature X enabled".
❓ Predict Output
advanced2:00remaining
Output with macro value comparison
What will this program print when compiled and run?
C
#include <stdio.h> #define VERSION 3 int main() { #if VERSION >= 5 printf("Version 5 or higher\n"); #elif VERSION == 3 printf("Version 3 detected\n"); #else printf("Older version\n"); #endif return 0; }
Attempts:
2 left
💡 Hint
Look at the value of VERSION and the #if conditions.
✗ Incorrect
VERSION is 3, so the #elif VERSION == 3 block runs, printing "Version 3 detected".
❓ Predict Output
expert3:00remaining
Output with complex conditional compilation and macro undefinition
What is the output of this program?
C
#include <stdio.h> #define MODE 1 #if MODE == 1 #define FEATURE_A #elif MODE == 2 #define FEATURE_B #endif #undef MODE int main() { #ifdef FEATURE_A printf("Feature A active\n"); #endif #ifdef FEATURE_B printf("Feature B active\n"); #endif #ifdef MODE printf("Mode defined\n"); #else printf("Mode undefined\n"); #endif return 0; }
Attempts:
2 left
💡 Hint
Check which macros are defined and which are undefined after #undef.
✗ Incorrect
MODE is initially 1, so FEATURE_A is defined. Then MODE is undefined. So output prints "Feature A active" and "Mode undefined".