Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to include the header file utils.h in main.c.
C
#include [1] int main() { return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using angle brackets for user header files.
Forgetting to include the header file.
✗ Incorrect
In C, to include a header file from the project, angle brackets < > are used for system headers, but for user headers, double quotes " " are used. Here, since utils.h is a user header, it should be included with double quotes.
2fill in blank
mediumComplete the function declaration in utils.h to declare a function named add that takes two integers and returns an integer.
C
int [1](int a, int b); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name than 'add'.
Omitting the semicolon at the end.
✗ Incorrect
The function name should be 'add' as specified. The declaration matches the function signature.
3fill in blank
hardFix the error in utils.c by completing the function definition of add.
C
int [1](int a, int b) { return a + b; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name in definition than declaration.
Mismatched function signatures.
✗ Incorrect
The function definition must match the declaration name 'add' to link correctly.
4fill in blank
hardFill both blanks to correctly compile main.c and utils.c into an executable named program.
C
gcc [1] [2] -o program
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Compiling only one source file.
Using wrong file names.
✗ Incorrect
To compile multiple source files, list them all in the gcc command. Here, main.c and utils.c are compiled together.
5fill in blank
hardFill all three blanks to create a header guard in utils.h to prevent multiple inclusions.
C
#ifndef [1] #define [2] // function declarations #endif // [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different macro names in the guard.
Forgetting to add header guards.
✗ Incorrect
Header guards use a unique macro name. Using the same macro name in all three places prevents multiple inclusions.