Chapter 5: Problem 21
How does a value-returning function differ from the void functions?
Short Answer
Expert verified
Answer: The primary differences between value-returning and void functions are:
1. A value-returning function returns a value to the calling function, whereas a void function does not. For example, a function `int add(int a, int b)` returns the sum of two integers.
2. A value-returning function has a specified return type, while a void function uses the 'void' return type. For example, `int add(int a, int b)` has a return type 'int', while `void print_hello()` has a 'void' return type.
3. A value-returning function uses the 'return' statement to pass the value back to the calling function, while a void function does not require a 'return' statement. For instance, the `add` function returns the sum using `return sum;`, whereas the `print_hello` function does not have a 'return' statement, just executes a statement within its scope.
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.