简体   繁体   English

具有相同数据的两个C空指针是否是不同的存储对象?

[英]Are two C void pointers with the same data different memory objects?

For example: 例如:

void *p1 = someStringPointer;
void *p2 = p1;

Although these are two unique pointers, given that they both point to the same value, are they still different memory objects? 尽管它们是两个唯一的指针,但鉴于它们都指向相同的值,它们是否仍是不同的内存对象?

If you print the address of p1 and p2 如果打印p1p2的地址

printf("%p\n", (void *) &p1);
printf("%p\n", (void *) &p2);

They have different addresses, so yes they are different memory objects. 它们具有不同的地址,所以是的,它们是不同的存储对象。

p1p2位于内存上的两个不同地址(在本例中为堆栈区域),但是它们包含相同的值,它们的值是someStringPointer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM