-
Adress of a pointer.
I am trying to assign adress of a pointer to a pointer.
so far:
Code:
#include <stdio.h>
#include <string.h>
int main()
{
int *ptr;
int y;
int **ptr2;
ptr=&y;
ptr2=&ptr;
printf("%p %p",ptr,ptr2);
return 0;
}
So According to what I think , every pointer has also an adress of their own which has the information about the adress that pointer points. Am I true?
-
You're right.
A pointer is a variable that contains a memory address as its value, just like ints have an integer as a value. And since pointers take up small parts of memory like other types of variables, information about the pointer itself is stored at an address that is very different from its value. So if that made sense, then yeah, pointers can have the location of other pointers as values.
But the thing is, no variable is aware of its own address. Hence, C has an operator that will fetch it for you.
Dereferencing T *p is something different. It's another operator that returns the T stored in its value.
-
Thanks perfect gentleman =)