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:
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