Monday, July 4, 2011

Dereference Operator(*)

We know that pointer is a variable that holds memory address of another variable. We can directly access the value of a variable using a pointer pointing to address of that variable. For this we will use the indirection operator (*) also known as dereference operator(*).  By placing the dereference operator before a pointer variable, we can access the variable whose address is stored in the pointer. Let us an Example:
                int a=65;
                int *p=&a;
Now, in our program, if we place '*' before p then we can access the variable whose address is stored in p. Since p contains address of  variable a, we can access variable a by writing *p. So we can use *p in place of varible name a. For Example.
*p=2 is equivalent to a=2..
(*p)++ is equivalent to a++.
The dereference operator can be read as "value pointed by" or "value at the address". For example * p can be read as "value at the address p" or " value pointed by p".

No comments:

Post a Comment