Reference vs Pointer

Differences

POINTERREFERENCE
Is a variable that holds memory address of another variable. // int *ptr = &i; Is an alias i.e. another name for an already existing variable. // int &ref = i;
Can point nowhere e.g. NULLMust refer to an object
Can be re-assigned any number of times Cannot be re-assigned after binding
Can take the address of a pointer Can’t take the address of a reference

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Up ↑

Design a site like this with WordPress.com
Get started