What is the main purpose of a header guard in C++?

Options

  • A. To prevent a header file from being included multiple times in one translation unit
  • B. To increase the size of the executable
  • C. To execute the main function automatically
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. To prevent a header file from being included multiple times in one translation unit

Detailed Explanation

Correct Answer: Option A

Explanation: Header guards using #ifndef, #define, and #endif prevent repeated inclusion of the same header contents within a translation unit, helping avoid redefinition errors.