What is the role of the return statement in C?
a) It terminates a function and optionally returns a value
b) It prints a value to the console
c) It allocates memory
d) It declares a global variable
Answer:
a) It terminates a function and optionally returns a value
Explanation:
The return statement in C is used to terminate the execution of a function and optionally return a value to the calling function. When a return statement is executed, the function ends, and control is passed back to the point where the function was called. If the function has a non-void return type, the return statement must include a value to be returned. For example, in a function that returns an integer, return 0; would return the value 0 to the caller.
Understanding the return statement is essential for controlling the flow of functions and passing data between functions in C programs.