Difficulty: Medium
Correct Answer: There is no default return type; a function must explicitly declare its return type or the compiler reports an error.
Explanation:
Introduction / Context:
Older versions of some programming languages, such as very early C compilers, sometimes assumed a default return type for functions when none was explicitly declared. Modern language standards and database languages such as PL SQL have moved away from this practice in order to improve type safety and code clarity. This question addresses the current expectation about function return types in contemporary strongly typed environments.
Given Data / Assumptions:
Concept / Approach:
In PL SQL, every function must declare a return type explicitly using the RETURN clause. Failing to do so results in a compilation error. Modern C standards also require function prototypes with declared return types, and compilers typically issue errors rather than silently assuming a default type. The idea of a default int return type is largely historical and discouraged. Therefore, in current practice, there is effectively no default return type; one must be specified.
Step-by-Step Solution:
Step 1: Recall that PL SQL requires every function to declare its return type as part of the function specification.
Step 2: Recognise that modern C compilers in standards compliant modes require function declarations with explicit return types.
Step 3: Understand that omitting the return type results in compilation errors or at least strong warnings in contemporary environments.
Step 4: Compare this reality with the answer choices and look for the option that states there is no default.
Step 5: Select the statement that accurately reflects that a function must explicitly declare its return type.
Verification / Alternative check:
If you attempt to create a PL SQL function without specifying a return type, the compiler rejects the definition. Similarly, in a modern C compiler with standards compliance enabled, declaring a function without a return type produces an error about an old style or missing type. These observations confirm that there is no default type that is silently assumed in strict, modern environments.
Why Other Options Are Wrong:
Option A, int, reflects an outdated convention from early C compilers and does not apply to PL SQL or current strict compilers. Options B, C, and E, suggesting char, string, or boolean as default types, are not supported by language specifications or common implementations. None of these languages silently assign those types as defaults for undeclared functions.
Common Pitfalls:
Students sometimes rely on old exam questions or legacy code examples that mention default int return types and assume this still applies. This can lead to incorrect code that fails to compile in modern environments. It is safer to always specify the return type explicitly and to avoid relying on any implicit default behaviour.
Final Answer:
In modern strongly typed environments, there is no default return type; a function must explicitly declare its return type or the compiler reports an error..
Discussion & Comments