+ 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.

24th Sep 2018, 8:22 AM
Sandeep Kushwaha
Sandeep Kushwaha - avatar
3 Respuestas
+ 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
24th Sep 2018, 8:31 AM
Aleksander Szczepura
Aleksander Szczepura - avatar
+ 3
In python everything is public.you can return value from function easily. x=3 def h(): return x print(h()) #output=3
24th Sep 2018, 4:08 PM
Maninder $ingh
Maninder $ingh - avatar
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().
24th Sep 2018, 11:36 PM
Abhishek Kumar
Abhishek Kumar - avatar