Practice mode C Language

What is the purpose of wrapping a header file in #ifndef MYHEADER_H, #define MYHEADER_H and #endif?

Correct answer B. To stop the header's contents being processed more than once in a translation unit

Explanation

This is an include guard. The first inclusion defines MYHEADER_H, so if the header is included again, directly or through another header, the #ifndef test fails and the contents are skipped. That prevents errors such as a struct being defined twice. Many compilers also support the non-standard #pragma once for the same purpose.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.