Yeah lol and there are many many more reasons to use pointers instead of variables. Such as if you want to access an array.
Say you have an array of like 5 Million integers and you need to pass that array to a function. Instead of copying that huge array you can just pass a reference to it like this.
- Code: Select all
int Array[5000000];
void function(int* pIntegers)
{
//do stuff
}
function(&Array);
There are really many many reasons to use pointers. You just have to be creative and think about what you can do with them.
And yes, the address is a memory address.
* = dereferences an address, or gets the information stored at an address in the memory.
& = reference address, or gets the address of the information stored in the memory.
You can even get the address of a pointer and assign it to a double pointer.
- Code: Select all
int X;
int A;
int *pX; //my integer pointer
int **ppX; //my pointer to an integer pointer
int ***pppX; // my pointer to and integer pointer pointer
X = 3;
pX = &X;
ppX = &pX;
pppX = &ppX;
A = *pX; // A = X
A == 3 // or A == X
A == **ppX // A == 3
***pppX = 22; // X = 22
pX = &A;
X == 22;
A == 3;
***pppX == 3; //pppX points to ppX which points to pX which points to A which has the value of 3
***pppX = 55;
X == 22;
A == 55;
Kind of confusing when you start putting more layers on but also know that pointers can be dereferenced a more readable way.
Continuing from above:
- Code: Select all
pppX->ppX->pX->A == 55;