The answers necessarily depend on the compiler, architecture, the ABI etc.
In what follows, I assume that the parameters in question are actually passed on the stack and not in registers (big assumption!), and there are no aggressive optimizations.
In case A, the parameter is passed by-value, does it mean that it will consume sizeof(short int) bytes?
No, it will consume sizeof(long int)
bytes since it will be widened first to match MyFunction()
's signature.
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
In a word, yes. You can't pass a short&
where a long&
is expected, so I assume you meant that you're passing a long&
here.