What is a Pointer?
In simple words, a pointer is an address. It is a derived data type that stores the memory address. A pointer can also be used to refer another pointer, function. A pointer can be incremented/ decremented, i.e., to point to the next/ previous memory location.
How does Pointer Work?
If we declare a variable v of type int, v will actually store a value.
v is equal to zero now.
However, each variable, apart from value, also has its address (or, simply put, where it is located in the memory). The address can be retrieved by putting an ampersand (&) before the variable name.
If you print the address of a variable on the screen, it will look like a totally random number (moreover, it can be different from run to run).
Let's try this in practice.
The output of this program is -480613588.
Now, what is a pointer? Instead of storing a value, a pointer will y store the address of a variable.
Int *y = &v;
VARIABLE |
POINTER |
A value stored in a named storage/memory address |
A variable that points to the storage/memory address of another variable |