两个指针变量可以指向相同的内存地址吗? [英] Can two pointer variables point to the same memory Address?
问题描述
如果 p
和 temp
是两个指针变量,其中 p
包含 NULL
和 temp
指向某个内存地址.
If p
and temp
are two pointer variables where p
contains NULL
and temp
points to some memory address.
现在假设 p = temp;
这意味着现在 p
指向与 temp
指向的地址相同的地址.
That means now p
points to same address as where temp
is pointing.
这是否意味着两个指针变量 p
和 temp
现在指向相同的内存地址?
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:
指针是变量,其值是C对象的地址或空指针.
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;
这是另一个包含单个元素的双向链接循环列表的示例: next
和 prev
链接都指向同一位置,即结构本身:
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 };
这篇关于两个指针变量可以指向相同的内存地址吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!