A variable is a named memory location used to store a value of a particular data type.
Pointers store the memory address of another variable.
int x = 5;
int* ptr = &x;
cout << *ptr; // 5
Feature | Pointer | Reference |
---|---|---|
Syntax | * , & | & only |
Reassignment | Can be reassigned | Cannot |
Nullability | Can be null | Must refer to an object |
Use Cases | More flexible | Safer and simpler for parameter passing |