Difficulty: Easy
Correct Answer: No
Explanation:
Introduction / Context:
Functions in C can return values, but many procedures exist solely for their side effects. Understanding return types, especially void, is fundamental to API design and reading system headers (for example, qsort callbacks, signal handlers with defined signatures).
Given Data / Assumptions:
Concept / Approach:
A function declared with void return type does not return a value (for example, void log_msg(const char*)). Returning a value from a void function is ill-formed. Conversely, a non-void function must return a value along every control path to avoid undefined behavior. Therefore, “every function must return a value” is false in general because void functions are perfectly valid and common.
Step-by-Step Solution:
Verification / Alternative check:
Review standard headers such as stdlib.h (e.g., void qsort). You will find many void-return functions in the standard library and typical codebases.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing a function that returns no value (void) with falling off the end of a non-void function, which is undefined behavior.
Final Answer:
No.
Discussion & Comments