Difficulty: Medium
Correct Answer: There is effectively no difference: both declare fun as a function that returns int and has external linkage, and neither one by itself provides a definition
Explanation:
Introduction / Context:
This question checks your understanding of function declarations, extern, and linkage in C. Many programmers are confused about when extern is necessary and what default linkage rules apply to functions declared at file scope.
Given Data / Assumptions:
Concept / Approach:
In C, a function declaration at file scope without a storage class specifier, such as int fun();, has external linkage by default. That means the function can be defined in this or another translation unit and can be called from other files. Adding extern explicitly, as in extern int fun();, does not change the meaning for functions; it simply makes the external linkage explicit. In both cases, these lines are declarations, not definitions, because they do not provide a function body.
Step-by-Step Solution:
Step 1: Consider int fun(); at file scope. This declares a function named fun that returns int and has external linkage by default.Step 2: Consider extern int fun(); at file scope. This also declares the same function signature with external linkage, making the linkage explicit.Step 3: Neither line has a function body enclosed in braces, so neither is a definition.Step 4: From the perspective of the compiler and linker, both declarations are compatible and interchangeable function prototypes for the same external function.
Verification / Alternative check:
If you place either declaration in a header file and define fun in a separate C file, the program links and runs correctly. Switching between the two forms or using both in different translation units does not change behaviour, demonstrating that there is no practical difference in this context.
Why Other Options Are Wrong:
Option B incorrectly claims that int fun(); defines the function, but a definition in C requires a function body.Option C confuses functions and variables; the presence of parentheses clearly indicates a function declaration.Option D is false because extern int fun(); is valid C syntax and is commonly used.
Common Pitfalls:
Programmers sometimes overuse extern for functions, not realizing that it is usually redundant at file scope. The real place where extern is important is for variables with external linkage, where it separates declarations from the single definition.
Final Answer:
The correct statement is There is effectively no difference: both declare fun as a function that returns int and has external linkage, and neither one by itself provides a definition.
Discussion & Comments