C return types: “Functions cannot return a floating-point number.” Decide Yes or No.

Difficulty: Easy

Correct Answer: No

Explanation:

Introduction / Context:This question checks whether you recognize valid C function return types. In C, functions can return many scalar and aggregate types, including floating-point types such as float, double, and long double.

Given Data / Assumptions:

  • Standard ISO C type system applies.
  • We consider ordinary functions, not variadic specifics.

Concept / Approach:The C grammar permits any complete object type to be a function’s return type, except for array and function types (which adjust to pointers). Floating-point types are first-class citizens and are frequently returned by math functions (e.g., sqrt returns double). Therefore, the claim that functions cannot return floating-point numbers is false.

Step-by-Step Solution:Consider prototypes such as double sin(double x); float hypotf(float, float); long double expl(long double);These functions return floating results directly.Hence, the correct response is “No”.

Verification / Alternative check:Write a trivial function: double f(void){ return 3.14; } and print with printf("%f", f()); It compiles and runs as expected.

Why Other Options Are Wrong:Yes: contradicts widespread standard library practice.Only by pointer/struct: unnecessary; direct floating returns are allowed.ABI dependency: ABIs define calling conventions but do not remove support for floating returns in C.

Common Pitfalls:Forgetting to use the correct printf format specifier for the specific floating type; assuming floating results must be returned via pointers for performance.

Final Answer:No

More Questions from Functions

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion