If, for example, I have a small function:
int sum(int a, int b)
{
int result = a+b;
return result;
}
Here, the result
is a local variable which, from what I understand, should live only for the execution time of the function. How is the caller of this function able to retrieve the return value of the sum() function, which is nothing but the value of the local variable result
? Just wanted to know how values of local variables declared inside a function are returned back to the caller functions. I know this happens in the stack but I wanted to know how exactly how it happens.