Answer to Question #24394 in C++ for Prankur Verma
The value of expression, if present, is returned to the calling function. If expression is omitted, the return value of the function is undefined. Functions of type void, constructors, and destructors cannot specify expressions in the return statement; functions of all other types must specify an expression in the return statement.
The expression, if specified, is converted to the type specified in the function declaration, as if an initialization were being performed. Conversion from the type of the expression to the return type of the function can cause temporary objects to be created. See Temporary Objects for more information about how and when temporaries are created.
When the flow of control exits the block enclosing the function definition, the result is the same as it would be if a return statement with no expression had been executed. This is illegal for functions that are declared as returning a value.
A function can have any number of return statements.
The following example uses an expression with return to obtain the largest of two integers.
int max ( int a, int b )
return ( a > b ? a : b );
int nOne = 5;
int nTwo = 7;
printf_s("\n%d is bigger\n", max( nOne, nTwo ));
Need a fast expert's response?Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!