FAQ Part 4: Variables, Pointers, and References

What are variables in C++?

A variable is a named memory location used to store a value of a particular data type.

What are pointers?

Pointers store the memory address of another variable.

int x = 5;
int* ptr = &x;
cout << *ptr; // 5

What is the difference between pointers and references?

FeaturePointerReference
Syntax*, && only
ReassignmentCan be reassignedCannot
NullabilityCan be nullMust refer to an object
Use CasesMore flexibleSafer and simpler for parameter passing