return statement or return keyword

The return statement terminates the execution of a called function and returns control to the calling function. A return statement can also return a value (optional) to the calling function. 
रिटर्न स्टेटमेंट कॉल्ड फंक्शन के एक्सीक्यूशन को समाप्त कर, प्रोग्राम कंट्रोल को कालिंग फंक्शन पर भेजने का कार्य करता है। रिटर्न स्टेटमेंट द्वारा वैकल्पिक रूप से एक वैल्यू भी रिटर्न की जा सकती है।    
Syntax:-
return expression_value;

Example:-
C++ program to show the use of return statement.
#include<iostream.h>
#include<conio.h>
long int factorial(int n){
int i;
long int fact=1;
for(i=1;i<n;i++){
fact=fact*i;
}
return fact;
}
void main(){
long int f;
int x;
clrscr();
cout<<"Enter a positive integer number"<<endl;
cin>>x;
f=factorial(x);
cout<<"factorial of "<<x<<" = "<<f<<endl;
getch();
}

No comments:

Post a Comment