Return statement - Control Structures

How is return statement used in C++?


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.


return expression;

Example :

#include <iostream.h>
void main()
int x,y,h;
cout << "The Highest number is::" << h << endl;
int max(int l, int m)
if (l > m)
return l;
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".

C++ Tutorial

Ask Questions

Ask Question