注册 登录
编程论坛 C++教室

[求助]void*的用法

yandongdido 发布于 2007-09-17 22:05, 571 次点击
如果声明指针是void*,它意味着任何型的地址都可以间接引用那个指针
那么,在*((int *)p)=3中是不是在把空指针改了以后,成为整形的,就一直是整形的 不能改变吗 ????
2 回复
#2
HJin2007-09-17 22:29

void* is called the generic pointer --- every pointer is 4 bytes (32-bit os) so that you can cast between different pointer types.

*((int*)p) = 3;

only says that the content of the memory location to which p points is 3.

It does not say p is a void*, or a int*.

#3
yandongdido2007-09-18 16:02
哦好象说的有道理,那让我在仔细看看把
谢谢了!
1