Difficulty: Medium
Correct Answer: Error: in prototype declaration unknown struct emp
Explanation:
Introduction / Context:This question examines how C handles tags (struct names) with respect to declarations and prototypes. Using a structure tag in a function prototype before the tag is declared requires at least a forward declaration of the tag.
Given Data / Assumptions:
Concept / Approach:In C, identifiers must be declared before use. A struct tag introduces a distinct namespace. To mention struct emp in a prototype prior to the full definition, you must forward declare it: struct emp; After that, the prototype may use struct emp safely, and the full definition can follow.
Step-by-Step Solution:
1) The prototype references struct emp before the compiler has seen any declaration of that tag.2) Without a prior tag declaration, the compiler reports that struct emp is unknown at the prototype.3) Fix: add a forward declaration line struct emp; above the prototype, or move the full struct definition above the prototype.Verification / Alternative check:Adding struct emp; makes the code compile; modify then increments age by 2 and the program prints "Sanjay 37".
Why Other Options Are Wrong:
Common Pitfalls:Assuming prototypes can reference undeclared tags; forgetting that struct tags form their own namespace and need forward declarations when used early.
Final Answer:Error: in prototype declaration unknown struct emp
Discussion & Comments