DEV Community

shuyueW1991
shuyueW1991

Posted on

difference of pointer and reference in storage

A pointer registers the address in memory of a variable. Therefore, the pointer value is the address.

A reference is a variable that contains the address of the targeted variable. More than 1 reference can be applied to a targeted variable; they can be pointed to the same address of the targeted variable.

In my opinion, their difference is more on the perspective of practice. For the targeted variable, if you want to manipulate it, it just offers you ONE pointer; whereas, the reference, there can be many, whilst saving redundant memory consumption.

Top comments (0)