Return statement – Control Structures

Return statement – Control Structures

How is return statement used in C++?

Explanation

Return Statement stops the execution of the code and returns the flow of the program to the calling function. The “return” function may or may not return a value. Usually all non-void functions must return a value. This belongs to control structures.

Syntax:

return expression;

Example :

#include
void main()
{
int x,y,h;
x=10;
y=20;
h=max(x,y);
cout << "The Highest number is::" << h << endl;
}
int max(int l, int m)
{
if (l > m)
{
return l;
}
else
{
return m;
}
}

Result :

The Highest number is::20

In the above example, the return statement control structure is explained in the following manner. the “main()” is a void function so it does not return a value, but the “max” function returns an integer value since its return type is “int”.





Leave a Reply

Your email address will not be published. Required fields are marked *