Difficulty: Medium
Correct Answer: Compile Error
Explanation:
Introduction / Context:
Function prototypes in C establish both return type and parameter types for type checking. A mismatch between the prototype and the actual definition leads to diagnostics because the compiler and linker can no longer agree on how arguments are passed or how the function should be called.
Given Data / Assumptions:
Concept / Approach:
With a prototype in scope, the compiler enforces argument type compatibility. Here, the prototype declares a single float parameter, but the definition provides a single int parameter—this is a type conflict. The compiler must emit a diagnostic (conflicting types/argument mismatch). Older K&R-style, no-prototype calls might allow implicit int promotions, but once a conflicting prototype is present, it is an error.
Step-by-Step Solution:
Compiler reads prototype: expects float.Compiler sees definition: parameter is int.Types differ → conflicting types for “fun”.Compilation fails; no well-defined output exists.
Verification / Alternative check:
Fix either side to match (both as int or both as float). Then, with fun(int) and argument 3.14, the literal would convert to int (likely 3), pre-increment to 4, and print 4—if types matched.
Why Other Options Are Wrong:
A/D reflect a hypothetical fixed program, not the mismatched one. B is impossible since printf("%d") prints integers. C is not mandated. The only correct outcome for the given code is a compile-time error.
Common Pitfalls:
Relying on implicit int or no-prototype calls; forgetting that mismatched prototypes and definitions must be identical in parameter types and return types.
Final Answer:
Compile Error
Discussion & Comments