Possible Duplicate:
What’s the difference between passing by reference vs. passing by value?
I know that the title can represent many other answered questions, I believe that my very specific question wasn't answered in other threads (I have searched, sorry if it's a duplicate).
To business: consider the next signatures:
A:
void MyFunction(long int x);
B:
void MyFunction(long int & x);
and the next usage:
void main()
{
short int y = 0;
MyFunction(y);
...
}
My question is related to the memory consumption of the parameter in the memory stack frame of MyFunction.
In case A, the parameter is passed by-value, does it mean that it will consume sizeof(short int) bytes?
In case B, the parameter is passed by-reference, assuming the compiler will implement it with a pointer, does it mean it will consume sizeof(pointer_type) bytes - which is probably more than short int? (I was once told that when using a reference it might consume 64 bits anyway, depending on the platform)
Note that the function receives long int type as I would like to know if it has any effect in both cases.
And another tiny question - can anyone post an example in which the compiler will NOT implement by-reference passed parameter using a pointer?
Thanks, Asaf.