Thursday, December 19, 2013

C C++ C#

If a pointer variable has the same address as its value, is it really pointing to itself?

For example - in the following piece of code, is a a pointer to itself?


int main(){
int* a;
int b = (int)&a;
a = b;
printf("address of a = %d\n", &a);
printf(" value of a = %d\n", a);

If a is not a pointer to itself, then the same question poses again: Can a pointer point to itself?
Also, how is a self pointing pointer useful?