0
0
Cprogramming~10 mins

Why preprocessor is used - Test Your Understanding

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

Complete the code to include a header file using the preprocessor directive.

C
#include [1]stdio.h[2]
Drag options to blanks, or click blank then click option'
A<>
B[]
C{}
D""
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes instead of angle brackets for standard headers.
Forgetting the #include directive.
2fill in blank
medium

Complete the code to define a constant using the preprocessor.

C
#define [1] 100
Drag options to blanks, or click blank then click option'
Aprintf
Bint
Cmain
DMAX_SIZE
Attempts:
3 left
💡 Hint
Common Mistakes
Using keywords like int or main as constant names.
Not using uppercase for constants.
3fill in blank
hard

Fix the error in the conditional compilation directive.

C
#if [1]
    printf("Debug mode\n");
#endif
Drag options to blanks, or click blank then click option'
ADEBUG = 1
Bdefined(DEBUG)
CDEBUG == 1
DDEBUG > 0
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment (=) instead of comparison (==).
Not using defined() to check macro existence.
4fill in blank
hard

Fill both blanks to create a macro that calculates the square of a number.

C
#define SQUARE([1]) ([2] * [2])
Drag options to blanks, or click blank then click option'
Ax
By
Cz
Dnum
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the parameter in the macro body.
Forgetting parentheses around the expression.
5fill in blank
hard

Fill all three blanks to create a macro that returns the maximum of two values.

C
#define MAX([1], [2]) (([3]) > ([2]) ? ([3]) : ([2]))
Drag options to blanks, or click blank then click option'
Aa
Bb
Cx
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing parameter names in the macro body.
Not using parentheses properly.