0
0
Cprogramming~10 mins

Conditional compilation - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
ARELEASE
BTEST
CLOGGING
DDEBUG
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
2fill in blank
medium

Complete 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'
AMAX_SIZE
BMIN_SIZE
CBUFFER_LEN
DCOUNT
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
3fill in blank
hard

Fix 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'
A"VERSION"
BVERSION == 2
CVERSION
Ddefined(VERSION)
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'VERSION == 2' inside the #if directive incorrectly
Putting quotes around VERSION
Using defined() when comparing values
4fill in blank
hard

Fill 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'
AFEATURE_X
BFEATURE_Y
CDEBUG
DRELEASE
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the feature names in the conditions
Using defined() incorrectly
Forgetting the negation operator !
5fill in blank
hard

Fill 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'
AMODE
B10
C20
DVALUE
Attempts:
3 left
💡 Hint
Common Mistakes
Using VALUE instead of MODE in the condition
Swapping the values 10 and 20
Forgetting to use #define