Return statement vs exit statement:
-return not close the entire program while exit() close the program.
-return statement may return some value from the function to the function calling but exit() not return any value.
-return value also depend on the return type of the function while exit() work anywhere in the program.
Return program:
#include < iostream>
using namespace std;
int sqaure(int n)
{
return n*n;
cout<<"This is after return";
}
int main()
{
int n,a;
cout<<"Enter number";
cin>>n;
a=sqaure(n);
cout<<"sqaure is: "<< a;
return 0;
}
Enter number
3
sqaure is: 9
#include < iostream>
using namespace std;
int main()
{
cout<<"First linen";
exit(0);
cout<<"Second line";
return 0;
}
First line