只要存得下地址,变量就是指针 :
#include <iostream>
int main()
{
int a = 0;
long b = (long)&a;
std::cout << "&a : " << std::hex << &a << std::endl;
std::cout << " b : " << std::hex << b << std::endl;
std::cout << " a : " << std::dec << a << std::endl;
*(int*)b = 110;
std::cout << " a : " << a << std::endl;
*(int*)b = 10086;
std::cout << " a : " << a << std::endl;
return 0;
}
结果:
[root@jn cpp]# ./a.out
&a : 0x7ffdcf229e34
b : 7ffdcf229e34
a : 0
a : 110
a : 10086
[root@jn cpp]#