Pointers and references let you directly work with memory addresses and aliases for variables. Pointers store memory addresses, references act as alternate names for existing variables.
*
to declare pointers, &
to get an address, and &
again to declare a reference.
int* ptr = &value;
— pointer to value
int& ref = value;
— reference to value
*ptr
— dereference pointer (get value it points to)*ptr
or ref
affects the original value