0

how can we return a value from a function if variables inside a function cease to exist outside of that function?

The variable declared inside the function cease to exist after the last statement of the function is executed. So how can we return the value of sum in the program that adds two integers using a function?

3rd Jul 2017, 12:00 PM
Manisha
Manisha - avatar
2 Réponses
+ 1
3rd Jul 2017, 12:13 PM
Jojo
+ 1
Return by value. In such case that value will be copied from local variable before it will be ceased and no problem. I should notice that sometimes the copy operation could be expensive if you worry about performance.
3rd Jul 2017, 2:57 PM
soman