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?
2 Respostas
+ 1
Like this : using parameters.
https://code.sololearn.com/cTQU7jt30XO5/?ref=app
+ 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.