C typedef and extern syntax: which line is correct? 1) typedef long a; extern int a c; 2) typedef long a; extern a int c; 3) typedef long a; extern a c;

Difficulty: Medium

Correct Answer: 3 correct

Explanation:


Introduction / Context:
This checks precision with C declarations. After introducing a typedef name, you must use it as a standalone type specifier. Mixing it with conflicting specifiers leads to invalid syntax or redeclaration errors.



Given Data / Assumptions:

  • The typedef name is a for long.
  • Goal: declare an external variable named c using that typedef.
  • We assume a single translation unit context; focus on syntax correctness.


Concept / Approach:
Once typedef long a; is processed, a is an alias for long and should be used by itself in place of long. A valid extern declaration using the alias is extern a c; which is equivalent to extern long c;. Combining a with another basic type keyword (like int) is invalid because a already denotes a complete type.



Step-by-Step Solution:
Line 1: extern int a c; → invalid: conflicts and malformed declarators.Line 2: extern a int c; → invalid: cannot combine typedef name a with int.Line 3: extern a c; → valid: equivalent to extern long c;.Therefore, only line 3 is correct.



Verification / Alternative check:
Compiling the three lines independently confirms that only the third form is accepted by a conforming compiler.



Why Other Options Are Wrong:
1 correct / 2 correct: both lines contain invalid combinations.All correct: contradicts compiler behavior.None are correct: false because line 3 is valid.



Common Pitfalls:
Forgetting that typedef names are type aliases, not modifiers; attempting to stack a with other base types; writing extern in a way that changes storage class rather than type.



Final Answer:
3 correct

More Questions from Declarations and Initializations

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion