Possible Duplicate:
pointer to a specific fixed address
int a, hex = 0x573285;
int * pA; // Pointer?
*pa = &a; // &a = the hexadecimal-memory location and *pa is now going to point to that place.
所以我想:
假设可以这样写,例如:
(*hex) = 5; or whatever the hexadecimal number is
改变内存的值?
如果我有一个程序(我不知道),它会显示我的游戏使用的所有内存位置。
如果我改变了程序中的值然后回到我的游戏或其他什么,它也会在那里改变吗? (如果游戏正在运行)。
(*this) 是否与 (this*)
相同?
编辑:
这行得通
int a = 5, b=0x28ff1c;
int* c = &a;
cout << *(c);
但不是:
int a = 5;
int * b=0x28ff1c;
int * c = &a;
cout << *(b);
也不是:
int a = 5, b=0x28ff1c;
int * c = &a;
cout << *(b);
你看到我想做什么了吗?
let's say it possible to write something like this for example:
(*hex) = 5; or whatever the hexadecimal number is
to change the value of the memory?
标准不一定保证这种能力,但在许多系统上你可以这样写:
*((int *) hex) = 5;
将hex
“转换”为指向int
的指针,然后取消对该指针的引用并将int
设置为5
— 当然,前提是 hex
中的值确实指的是您可以写入的某个内存位置。但不用说,您不应该在任何您实际打算使用做任何事情的程序中这样做。
if I had a program (I don't know one), that showed me all the memory locations my game use. if i changed the value in the program and then got back to my game or what ever, would it be changed there aswell? (if the game's running).
嵌入式系统通常是这种情况,但由于使用了 virtual memory 和 virtual address spaces ,因此在具有普通操作系统的现代机器上通常不是这种情况。发生的情况是,一个进程通常不会知道它正在使用的内存的真实物理内存位置(如果有的话);相反,存储在指针中的值是“虚拟的”,并且依赖于进程。两个进程的 0x12345678
可以完全没有关系,被映射到完全独立的内存位置。