DEV Community

shuyueW1991
shuyueW1991

Posted on

1

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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay