简体   繁体   中英

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

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

They have different addresses, so yes they are different memory objects.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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