Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to include the header file only if DEBUG is defined.
C
#ifdef [1] #include <stdio.h> #endif
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using #ifndef instead of #ifdef
Using a macro name that is not defined
Forgetting to close the #ifdef block with #endif
✗ Incorrect
The #ifdef directive checks if DEBUG is defined before including the code inside.
2fill in blank
mediumComplete the code to define a macro only if it is not already defined.
C
#ifndef [1] #define [1] 100 #endif
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Defining the macro without checking if it exists
Using a macro name that is unrelated to size
Forgetting to use #endif
✗ Incorrect
The #ifndef directive checks if MAX_SIZE is not defined before defining it.
3fill in blank
hardFix the error in the conditional compilation directive to check if VERSION is 2.
C
#if [1] == 2 printf("Version 2\n"); #endif
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'VERSION == 2' inside the #if directive incorrectly
Putting quotes around VERSION
Using defined() when comparing values
✗ Incorrect
Use the macro name VERSION directly in #if to compare its value to 2.
4fill in blank
hardFill both blanks to compile code only if FEATURE_X is defined and FEATURE_Y is not defined.
C
#if defined([1]) && !defined([2]) printf("Feature X enabled, Feature Y disabled\n"); #endif
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the feature names in the conditions
Using defined() incorrectly
Forgetting the negation operator !
✗ Incorrect
Use defined(FEATURE_X) and !defined(FEATURE_Y) to check the conditions correctly.
5fill in blank
hardFill all three blanks to define a macro VALUE as 10 if MODE is 1, else 20.
C
#if [1] == 1 #define VALUE [2] #else #define VALUE [3] #endif
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using VALUE instead of MODE in the condition
Swapping the values 10 and 20
Forgetting to use #define
✗ Incorrect
Check if MODE equals 1, then define VALUE as 10, else define it as 20.