1. Home
  2. Computer Science MCQs
  3. C Programming
  4. Why is #pragma once a weaker guarantee against double…

Added 30 Nov -0001

Why is #pragma once a weaker guarantee against double inclusion than a traditional include guard?

  1. It only works when the header is included with angle brackets, not quotes
  2. It prevents duplicate inclusion only inside a single translation unit
  3. It is non-standard, so a compiler may ignore it and reprocess the header Correct answer
  4. It is standard since C99, but older preprocessors treat it as a comment

Correct answer

C. It is non-standard, so a compiler may ignore it and reprocess the header

20 views

MCQSEXAM

Explanation

#pragma once is a widely supported extension rather than a feature of the C standard, so a conforming compiler may ignore the directive and include the file again. A guard built from #ifndef, #define and #endif relies only on macro semantics and is fully portable. Both mechanisms work per translation unit, which is why neither prevents the same header from being included in two different source files.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs