0
0
Cprogramming~10 mins

Header files and include directive - 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 standard input-output header file.

C
#include [1]

int main() {
    printf("Hello, world!\n");
    return 0;
}
Drag options to blanks, or click blank then click option'
A"stdio.h"
B<stdio.h>
C<stdlib.h>
D"stdlib.h"
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes instead of angle brackets for standard headers.
Including the wrong header file like stdlib.h.
2fill in blank
medium

Complete the code to include a user-defined header file named "myheader.h".

C
#include [1]

void greet();

int main() {
    greet();
    return 0;
}
Drag options to blanks, or click blank then click option'
A"myheader.h"
B<myheader.h>
C<stdio.h>
D"stdio.h"
Attempts:
3 left
💡 Hint
Common Mistakes
Using angle brackets for user-defined headers.
Including the wrong header file.
3fill in blank
hard

Fix the error in the include directive to correctly include the math header.

C
#include [1]

int main() {
    double result = sqrt(16.0);
    return 0;
}
Drag options to blanks, or click blank then click option'
A<math>
B"math.h"
C<math.h>
D"math"
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the .h extension.
Using quotes instead of angle brackets.
4fill in blank
hard

Fill both blanks to include the header and declare a function prototype.

C
#include [1]

[2] greet();

int main() {
    greet();
    return 0;
}
Drag options to blanks, or click blank then click option'
A"myheader.h"
Bvoid
Cint
D<stdio.h>
Attempts:
3 left
💡 Hint
Common Mistakes
Using angle brackets for user headers.
Omitting the return type in function prototype.
5fill in blank
hard

Fill all three blanks to create a header guard in a header file.

C
#ifndef [1]
#define [2]

void greet();

#endif // [3]
Drag options to blanks, or click blank then click option'
AMYHEADER_H
DGREET_H
Attempts:
3 left
💡 Hint
Common Mistakes
Using different macro names in the guard.
Omitting the header guard entirely.