My little understanding about pointers and references

consider the following C++ code snippet.


...
int x = 100;
int &xref = x;
int y = 200;
xref = y;
...


obviously, this is erroneous. But why? I am yet to find out. I was told by my friend that references are internally const pointers to the type they are referring to. So they cannot be made to point to any other object.

What other differences are between references and pointers?

Pointers need dereferencing. References don’t.

Advertisements

One response to “My little understanding about pointers and references

  1. That’s a good one. 🙂

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s