A little help on return prototype
Code:
thanks |
because the function was declared; Therefore, when the function was called, it's return value would be taken.
If you'd return by reference (if that's actually possible) there's a chance that you get a segv; I've no idea how compilers would go about that... never done returning by reference on a variable that would be destroyed from the heap. |
Be careful about words here: the heap is where malloc and its friends operate, and is global: you mean the stack. The answer is simple: the stack is cut back, losing the stack frame for the function, including parameters, and the return value is added to the top of the stack, in the stack frame for main. Since sum() is declared as int, the return value is dereferenced, if necessary, and returned as int.
You do not give the code for sum, so it is not clear if dereferencing is necessary. edit: You do not say how a and b are given values, or how the sum is constructed. If malloc is used, then the values really are on the heap and are global. For example, if you create space for an int inside sum() using malloc, then that still exists, even though (probably) inaccessible, since the pointer to it is lost when sum() returns. |
Quote:
In layman's terms: Code:
void function_one() |
Quote:
Code:
#include <string> Kevin Barry |
Quote:
Quote:
|
All times are GMT -5. The time now is 01:17 AM. |