Difficulty: Easy
Correct Answer: extern int a is declaration, int a = 20 is the definition
Explanation:
Introduction / Context:The C language distinguishes between declaration (introducing a name and type) and definition (allocating storage or providing a body). This is especially important for global variables, which are often declared in headers and defined in exactly one source file. The snippet uses 'extern int a;' and later 'int a = 20;'. We must identify which line declares and which line defines the object 'a'.
Given Data / Assumptions:
Concept / Approach:
Step-by-Step Solution:
Classify the 'extern' line → declaration without storage.Classify the 'int a = 20;' line → definition (creates the object and initializes it).Therefore, declaration is 'extern int a;' and definition is 'int a = 20;'.Verification / Alternative check:
If you remove 'int a = 20;' and link, you will get an unresolved external symbol for 'a'; adding the definition resolves the reference.Why Other Options Are Wrong:
Common Pitfalls:
Final Answer:
extern int a is declaration, int a = 20 is the definition
Discussion & Comments