If p
and temp
are two pointer variables where p
contains NULL
and temp
points to some memory address.
Now suppose p = temp;
That means now p
points to same address as where temp
is pointing.
Does that mean two pointer variables p
and temp
are now pointing to the same memory address?
Yes, two pointer variables can point to the same object:
Pointers are variables whose value is the address of a C object, or the null pointer.
multiple pointers can point to the same object:
char *p, *q;
p = q = "a";
a pointer can even point to itself:
void *p;
p = &p;
here is another example with a doubly linked circular list with a single element: the next
and prev
links both point to the same location, the structure itself:
struct dlist {
struct dlist *prev, *next;
int value;
} list = { &list, &list, 0 };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With