+ 1
How to return value by function in any programming language ?
In function having local variables and out side the function out of scope of local variables or destroyed in scope so how to return that value by the function. also try to explain how it's done by compiler.
3 Réponses
+ 4
Here you have an example of how to return value of function without using return keyword in c++(it allows you return more than one variable):
https://code.sololearn.com/cP7Te69U6rRY/?ref=app
+ 3
In python everything is public.you can return value from function easily.
x=3
def h():
return x
print(h()) #output=3
0
look its very simple , following eg. will explain how to do it in c++:
abhi();
int main(){
cout<<abhi()<<endl;
}
int abhi(){
int a,b,c;
cout<<"enter a and b"<<endl;
cin>>a;
cin>>b;
c=a+b;
return(0);
}
explanation:
here abhi() is the function that is returning c (an integer value) to the main function and via main() function we are giving output of abhi().