What is the output of the below code?
#include<stdio.h> int number(void); void main() { int num = number(); printf("%d",num); } int number() { return 0; return 1; return 2; }
----------------------------------------------------
In the above program number() is a calling function. When number() is called, the execution is passed to the number() function and inside that function we are trying to return 3 times using 3 return statements. However, with the first return, the execution is passed to the calling function and num is assigned 0. The output is hence 0.
return statement:
A return statement used in a C program ends the execution of a function in which return is used and returns control to the calling function. Execution resumes in the calling function at the point immediately following the call. A return statement can return a value to the calling function.
0 Comments