Difficulty: Easy
Correct Answer: Correct
Explanation:
Introduction / Context:
This item checks whether you understand that C allows multiple exit points from a function. A function can contain many return statements, each returning a value computed along a particular branch. The key constraint is that the returned expression must be compatible with the function’s declared return type.
Given Data / Assumptions:
Concept / Approach:
C does not restrict the number of return statements. This is frequently used for clarity: early returns for error handling and final returns for success paths. What matters is type correctness and that all code paths in a non-void function ultimately return a value.
Step-by-Step Solution:
Define function with type, e.g., int f(...).Use branches: if (err) return -1; else if (warn) return 0; else return 1;Each return provides a value of compatible type (int in this case).
Verification / Alternative check:
Compilers allow many returns; they only warn or error if a path lacks a return in a non-void function or the return type mismatches.
Why Other Options Are Wrong:
Incorrect: contradicts standard practice and the C grammar.Inline/debug/extension requirements: none apply; the rule is fundamental.
Common Pitfalls:
Forgetting to return a value along some path, causing undefined behavior; returning mismatched types (e.g., pointer where int is expected).
Final Answer:
Correct
Discussion & Comments