Before saying that this will be a repeating question and a downward one (as it was before), I searched and found nothing.
I, like many others, are trying to study the use of C ++ reference variables and associate them with pointers. It was easier for me to make the table, and I need to know if it needs to be fixed.
int *n int n int &n caller/local
void foo(int *n) n &n &n caller
void foo(int n) *n n n local
void foo(int &n) *n n n caller
The table wants to reflect all the parameters accepted by law.
[1,1]: passing by reference (trivial)
[1,2]: passing by reference
[1,3(1)]: passing by reference, an is an address(?)
[1,3(2)]: passing by reference, as n is used as alias(?)
[2,1]: passing by value, as dereferencing
[2,2]: passing by value (trivial)
[2,3(1)]: passing by value, using value of n (where n is an alias)
[2,3(2)]: passing by value (dereferencing n, which is an address)
[3,1(1)]: passing by reference, as foo accepts address
[3,1(2)]: passing by reference, reference of value at address n
[3,2(1)]: passing by reference (trivial)
[3,2(2)]: passing by reference, as foo accepts address or reference
[3,3]: passing by reference (trivial, as argument matches parameter exactly)
- Are the tables and explanations correct?
- Are there any cases left outside the table (other than derivatives such as * & n, pointer to pointer, etc.)?
source
share