How do pointers in C++ work, and why are they different from references?

1.14K views

Edit: Perhaps I mean “how” are they different from references, not why.

In: Technology

3 Answers

Anonymous 0 Comments

A pointer is a variable that holds a memory address.

Your business card is a pointer, it tells me your address. Knowing that doesn’t tell me who’s in your house, I just know where to look if I want to know who’s there. Deferencing is like taking my knowledge of your address and using to drive to your house, go inside, and see who’s there.

A reference is basically an always dereferenced pointer. You’re always looking through the reference at the value of the referenced variable.

You are viewing 1 out of 3 answers, click here to view all answers.