Bird
0
0

Why is it recommended to put only declarations (not definitions) in header files in C?

hard📝 Conceptual Q10 of 15
C - Basics and Execution Environment
Why is it recommended to put only declarations (not definitions) in header files in C?
ATo make compilation faster
BBecause definitions are not allowed in headers
CTo avoid multiple definition errors during linking
DBecause declarations run faster than definitions
Step-by-Step Solution
Solution:
  1. Step 1: Understand difference between declaration and definition

    Declarations tell the compiler about functions or variables; definitions provide the actual code or storage.
  2. Step 2: Reason about multiple inclusion

    If definitions are in headers included multiple times, linker sees duplicates causing errors.
  3. Final Answer:

    To avoid multiple definition errors during linking -> Option C
  4. Quick Check:

    Definitions in headers cause multiple definitions = linker errors [OK]
Quick Trick: Headers declare; source files define to prevent duplicate code [OK]
Common Mistakes:
  • Thinking definitions are forbidden in headers
  • Believing declarations affect runtime speed
  • Assuming headers speed up compilation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes