A pointer is a variable that represents a location in memory; since every variable that you declare has a space in memory, pointers can "point" to the location of any variable. You can find a variable's memory location with the & operator, which returns a variable's address (a constant):
The output will be a hexadecimal number that will look something like "0x9e145450." You can create a pointer variable to store this location:
You can then access both the address of some_var, and the value of some_var using the pointer_var variable:
The variable name preceded by an asterisk evaluates to the stored value, whereas the variable name alone evaluates to an address. It is important to recognize the difference between the value of a variable and the variable's location in memory, so it may be worthwhile to reread the above paragraphs; pointers are often considered one of the most difficult aspects of programming to learn. A review of pointer basics can be found here.
Passing by reference
Pointers are often passed to functions. This is called "passing by reference." When you simply pass a variable instead of a pointer to it, you are "passing by value." For instance, the following will not work as the programmer might intend because the variable is passed by value:
When the function finishes, the program forgets what it did to value. This is because the function created an entirely new variable for value, which goes out of scope when the function returns. You must instead pass by reference by adding a & to the end of the argument data type: