The Indirection and Dereference operator
The ( * ) operator has two names, and they both fufill different roles. For example, it can be called the indirection operator, if it is used like this:
 | |  | | |
int Age = 16; // created a variable
int * pAge = &Age; // made a pointer to Age
|
|  |
|
Indirection means accessing the variables value at the address held by a pointer.
The above program used indirection also. As you can see the following code lines:
Okay, now I think you understand what indirection is, so we will move on to the next meaning of the ( * ) operator. The indirection operator ( * ) can also be called the dereference operator. Here is an example:
 | |  | | |
#include <iostream.h>
int main()
{
int Age = 54;
int *pAge = &Age; //Indirection operator being used…
cout <<"Here is the value of Age: " << Age << "n";
cout <<"Changing the value of Age using the dereference operator: " << "n";
*pAge = 4; //dereferencing
cout <<"New value of Age: " << Age << endl;
return 0;
} |
|  |
|
In this little program, I created a variable then used the Indirection operator to create a pointer and gave the pointer the address of Age. This means, whatever I change the pointer too, using the dereference operator ( * ), will change the value of the address its holding. In this case, the address the pointer was holding was the variable Age.
This last note will clear everything up I hope. The indirection operator declares a pointer, but the dereferencing operator gets the value at the address.
Please Rate this Code: