Recall & Review
beginner
What is a header file in C?
A header file in C is a file with extension
.h that contains declarations of functions, macros, and variables. It helps share code between different source files.Click to reveal answer
beginner
What does the
#include directive do?The
#include directive tells the compiler to copy the contents of a specified header file into the source file before compilation. It helps reuse code and declarations.Click to reveal answer
intermediate
Difference between
#include <file.h> and #include "file.h"?#include <file.h> searches for the header file in system directories.<br>#include "file.h" searches first in the current directory, then system directories.Click to reveal answer
intermediate
Why use header guards in header files?
Header guards prevent a header file from being included multiple times in the same source file, avoiding errors like redefinition of functions or variables.
Click to reveal answer
beginner
Example of a simple header guard in a header file?
#ifndef MYHEADER_H
#define MYHEADER_H
// Declarations here
#endif
This code ensures the header content is included only once.
Click to reveal answer
What is the main purpose of a header file in C?
✗ Incorrect
Header files declare functions and macros so multiple source files can use them.
Which directive includes a header file from the system directories?
✗ Incorrect
#include <file.h> searches system directories for the header file.What problem do header guards solve?
✗ Incorrect
Header guards stop the same header file from being included more than once.
Where does the compiler copy the contents of a header file?
✗ Incorrect
The preprocessor copies header file contents into the source file before compilation.
Which is the correct way to write a header guard?
✗ Incorrect
The pattern
#ifndef ... #define ... #endif is used for header guards.Explain what a header file is and why we use the #include directive in C.
Think about how multiple files share code.
You got /4 concepts.
Describe how header guards work and why they are important.
Imagine including the same file twice by mistake.
You got /3 concepts.