Maybe there is an answer to this, but I haven't found it, probably because I do not know what the correct title of my question is.
I'm starting to learn C++, and noticed that when initializing, modifying, and accessing, the behavior is the same in both of these lines.
int *p = &a;
and
int &p = a;
The only difference I see is that later when I use p
in the first case, I have to write *p
everytime, otherwise I get the address of (probably a
since its value equals &a
), whereas in the second case I can just write p
without the asterisk.
Are those just different syntax for the same thing, or are they different but just happen to give me the same results (in my very basic tests)? Is the compiler doing the same thing in both cases?