Answer the question
In order to leave comments, you need to log in
What is the difference between * and &?
Please tell me what is the difference between these two declarations:
Test *a;
Test &b;
Answer the question
In order to leave comments, you need to log in
A pointer is an address, and it is stored in a variable.
& This is a link. Like an alias to the place it refers to. There is a difference.
The reference cannot be changed, only the value in memory where the reference refers to can be changed. The link itself cannot be changed. The pointer can be changed. A constant pointer cannot be changed.
A reference cannot be uninitialized, a pointer can be.
A pointer can point to memory on the heap that must be freed, a reference never needs to be freed separately.
Plus, there are also r-value references (I think that's what they're called) &&. They cannot be assigned, only read.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question