Sunday, March 20, 2016

Dereferencing Pointers

As you seen earlier, "*" operator is used to declare the pointer type of the variable. "*" is also used to dereference the pointer also.
int j = *p;
It sets the value of "j" variable to the value contained at the memory address, the pointer p points to i.e. 10. You can also set a value to the memory address that a pointer holds like below.
*p = 20;
By this, the memory address that "p" pointer holds i.e. 0x2000 contains value 20 which is same as the value of i and *j, interesting right! That’s the beauty of the pointer, as you change the value that contains an address of a variable; it also changes the variable itself.

No comments: