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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

Create a free website or blog at WordPress.com.

Up ↑

Create your website at WordPress.com
Get started
%d bloggers like this: