Skip to main content
PProfileMatch
← Path

C++ · C++ Pointers and References Explained

0 XP
  1. 1 current stop: learning
  2. 2 upcoming
  3. 3 upcoming
  4. 4 upcoming
  5. 5 upcoming

Finish after stop 5

Stop 1 of 5 · Street map: house numbers

Trick to keep in mind+3 XP

& means where it lives; * means go there and look inside.

A pointer is just a variable whose value is an address. &balance produces that address, and *ptr follows it to the memory it names. Because the pointer and the original variable refer to the same memory, writing through the pointer changes the original, with no copy involved.

int balance = 1000;
int* ptr = &balance;
*ptr = 1500;   // balance is now 1500

Read it once, then a question tests whether the trick stuck.