Basics of Pointer

A limitation of function is that it can only affect your program via their return value, so what do you do when you want a function to alter more than one variable? At that time you use pointers. A pointer is a special kind of variable.

 Pointers are designed for storing memory address i.e. the address of another variable. Declaring a pointer is the same as declaring a normal variable except you add  '*' in front of the variables identifier.
There are two new operators you will need to know to work with pointers. The "address of" operator '&' and the "dereferencing" operator '*'. Both are prefix unary operators.

When you place an ampersand in front of a variable you will get it's address, this can be store in a pointer. When you place an asterisk in front of a pointer you will get the value at the memory address pointed to.

Back