我有一个指针,我可以在其中“手动”设置它指向的地址:
pPlayerPool = reinterpret_cast<DWORD*>(someAddress+PLAYER_POOL_POINTER_OFFSET);
游戏还没开始的时候,pPlayerPool
指向0x0,我的内存搜索工具里是这么写的。我试着检查一下
if(*pPlayerPool)
或
if(*pPlayerPool != 0)
或
if(*pPlayerPool != NULL)
当它是 0x0 时,我的程序总是崩溃。
然后我有另一个小问题:据我所知,*
为我提供了指针的值,而 &
为我提供了指针本身的地址。但是如果没有这些字符,这个值意味着什么?
最佳答案
那是因为您试图解引用一个空指针。不要取消引用它只是检查它的值。
if(pPlayerPool)
if(pPlayerPool != 0)
当你这样做的时候
*pPlayerPool != 0
您正在测试 pPlayerPool
所指向的 是否为零。并不是说 pPlayerPool
是血清。
关于c++ - 如何判断指针指向的地址是否为0x0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22262401/