Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start an include guard with the correct directive.
C
#[1] MY_HEADER_H
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using #define instead of #ifndef to start the guard.
Using #include instead of a preprocessor directive.
✗ Incorrect
The include guard starts with #ifndef to check if the macro is not defined.
2fill in blank
mediumComplete the code to define the macro for the include guard.
C
#ifndef MY_HEADER_H #[1] MY_HEADER_H
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using #ifndef again instead of #define.
Using #endif instead of #define.
✗ Incorrect
After checking if the macro is not defined, we define it with #define.
3fill in blank
hardFix the error in the code to properly close the include guard.
C
#ifndef MY_HEADER_H #define MY_HEADER_H // header content #[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using #define or #ifndef instead of #endif at the end.
Omitting the closing directive.
✗ Incorrect
The include guard ends with #endif to close the conditional.
4fill in blank
hardFill both blanks to complete a proper include guard.
C
#[1] MY_HEADER_H #[2] MY_HEADER_H // header content #endif
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of #ifndef and #define.
Using #include or #endif in these positions.
✗ Incorrect
The include guard starts with #ifndef and then #define to define the macro.
5fill in blank
hardFill all three blanks to write a complete include guard.
C
#[1] MY_HEADER_H #[2] MY_HEADER_H // content #[3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to close the guard with #endif.
Using #include instead of #define or #endif.
✗ Incorrect
The include guard starts with #ifndef, then #define, and ends with #endif.