Difficulty: Easy
Correct Answer: 20
Explanation:
Introduction / Context:
Linkage and declaration order in C often confuse newcomers. This example shows that a global can be declared before use and defined later in the same translation unit without issue.
Given Data / Assumptions:
Concept / Approach:
An extern declaration tells the compiler the name and type exist somewhere. A definition provides storage. The linker resolves references to the later definition in the same translation unit just fine. Output is the initialized value.
Step-by-Step Solution:
Compiler sees the declaration, allows usage in printf.Definition after main allocates storage and initializes to 20.Linker binds the reference to that definition.Program prints 20.
Verification / Alternative check:
Placing the definition before or after main() yields the same behavior; what matters is that one definition exists at link time.
Why Other Options Are Wrong:
B/C: The variable is explicitly initialized to 20. D/E: No compile or link error since declaration and definition are consistent.
Common Pitfalls:
Confusing declaration with definition; believing order within a single file restricts visibility (linker resolves it).
Final Answer:
20
Discussion & Comments