- #1
guguma
- 51
- 5
I am totally confused about one peculiar thing in C++.
The "&" as far as I know from C is used to access the address of a variable. When calling a variable by reference, I used to do it with the &'s and *'s (pointers).
I am taking a look at deitels' book on C++, I saw the same pointer structure in C++, it is totally normal but there is also this separate call by reference thing using the & and I do not understand that.
When I do
This looks to me as I am assigning the value of x to the address of y, where y is an undefined variable?
It is not reasonable. It must be some other thing. Can someone please explain to me how exactly call by reference works in the machine in terms of addresses and values.
And one other thing if & here does not mean "address" but something else, when I am writing a function which takes an address as an argument, how does the compiler differentiate between the two.
Thanks
The "&" as far as I know from C is used to access the address of a variable. When calling a variable by reference, I used to do it with the &'s and *'s (pointers).
I am taking a look at deitels' book on C++, I saw the same pointer structure in C++, it is totally normal but there is also this separate call by reference thing using the & and I do not understand that.
When I do
Code:
int x = 56, &y = x;
This looks to me as I am assigning the value of x to the address of y, where y is an undefined variable?
It is not reasonable. It must be some other thing. Can someone please explain to me how exactly call by reference works in the machine in terms of addresses and values.
And one other thing if & here does not mean "address" but something else, when I am writing a function which takes an address as an argument, how does the compiler differentiate between the two.
Thanks