Are you familiar with functions at all? Functions can help clarify the meaning of a pointer.
A basic function for say, adding 500 to an integer could look like this
1 2 3 4
|
int addNum(int x)
{
return (x + 500);
}
|
When this function is called, you would pass a value for x. This value of x is copied and then 500 is added to it and then returned.
This is called passing by value, because you made a copy of the value you wanted to add 500 to.
Now lets say we wanted to pass using a pointer. It may look something like this
1 2 3 4 5 6
|
void pointerNum(int* x)
{
*x += 500;
}
|
Notice how I did not return anything? Well, this is because I pulled the actual address of the variable and then used the deference operator to modify the variable. So this was not passed using a copy but passed by the address location, then modified.
The reason I explained this is to help understand why we use pointers. We use them because it is faster and uses less memory to pass around data. When dealing with a lot of data it uses a lot of resources to pass the data on top of trying to allocate more memory to make copies to modify it. Instead, you can modify it directly by knowing where it exists in memory and then knowing how to change it(deference).
In short, it is like emailing you a URL to a website instead of emailing the whole website to you.