Recall & Review
beginner
What is the main purpose of a header file in C?
A header file (.h) declares functions, macros, and variables so they can be shared between multiple source files (.c). It helps organize code and avoid repetition.
Click to reveal answer
beginner
Why should function definitions be placed in source files (.c) instead of header files (.h)?
Function definitions in source files avoid multiple definition errors during linking. Header files should only have declarations to allow sharing without duplication.
Click to reveal answer
intermediate
What is an include guard and why is it important?
An include guard is a set of preprocessor commands (#ifndef, #define, #endif) in a header file that prevents it from being included multiple times, avoiding redefinition errors.
Click to reveal answer
beginner
How do you include a header file in a source file?
Use the #include directive with quotes for your own headers, like #include "myheader.h". This tells the compiler to insert the header's content.
Click to reveal answer
intermediate
What is the benefit of separating declarations and definitions into header and source files?
Separating declarations and definitions improves code readability, allows multiple source files to share declarations, and helps manage large projects by modularizing code.
Click to reveal answer
Which file should contain the function implementation in C?
✗ Incorrect
Function implementations belong in source files (.c) to avoid multiple definitions and keep code organized.
What does an include guard prevent?
✗ Incorrect
Include guards prevent the same header file from being included more than once, avoiding redefinition errors.
How do you include a standard library header in C?
✗ Incorrect
Standard library headers are included with angle brackets, like #include .
Which of these is NOT typically found in a header file?
✗ Incorrect
Function implementations should be in source files, not header files.
Why use header files in a C project?
✗ Incorrect
Header files share declarations so multiple source files can use the same functions and types.
Explain how header and source files work together in a C program.
Think about how you tell the compiler about functions before using them.
You got /4 concepts.
Describe the role and structure of an include guard in a header file.
It's like a safety check to avoid repeating the same code.
You got /3 concepts.