0
0
Cprogramming~10 mins

Header and source file organization - 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 in the source file.

C
#include [1]
Drag options to blanks, or click blank then click option'
A"stdio.h"
B<stdio.h>
C<myheader.h>
D"myheader.h"
Attempts:
3 left
💡 Hint
Common Mistakes
Using angle brackets for your own header files.
Forgetting the quotes or brackets around the header name.
2fill in blank
medium

Complete the header guard to prevent multiple inclusion.

C
#ifndef [1]
#define MYHEADER_H

// function declarations

#endif
Drag options to blanks, or click blank then click option'
AMYHEADER_H
BMY_HEADER_H
Cmyheader_h
DMYHEADER
Attempts:
3 left
💡 Hint
Common Mistakes
Using different macro names in #ifndef and #define.
Using lowercase or missing underscores.
3fill in blank
hard

Fix the error in the header file to correctly match the header guard macro.

C
#ifndef [1]
#define MY_HEADER_H

void greet();

#endif
Drag options to blanks, or click blank then click option'
AMYHEADER_H
BMY_HEADER_H
CMYHEADERH
DMY_HEADERH
Attempts:
3 left
💡 Hint
Common Mistakes
Missing underscores in macro names.
Mismatch between #ifndef and #define macro names.
4fill in blank
hard

Fill both blanks to declare and define a function properly across header and source files.

C
// In myheader.h
void [1]();

// In mysource.c
#include "myheader.h"

void [2]() {
    printf("Hello!\n");
}
Drag options to blanks, or click blank then click option'
Agreet
Bhello
Cprint
DsayHello
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names in declaration and definition.
Forgetting to include the header file in the source file.
5fill in blank
hard

Fill all three blanks to create a dictionary-like structure using structs and initialize it.

C
typedef struct {
    char* [1];
    int [2];
} [3];

[3] item = {"apple", 5};
Drag options to blanks, or click blank then click option'
Aname
Bquantity
CItem
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent field names.
Not matching the struct type name in declaration and initialization.