如何保存指针最初指向的原始值

How to save the original value of what pointer initially points to

本文关键字:原始 指针 何保存 保存      更新时间:2023-10-16

新程序员在这里...任何帮助将不胜感激...

在下面的示例中,我将如何在 : 0x4000000 处保留原始值,以便一旦我这样做:(整数((0x4000000( = 900;我仍然可以拥有在我将其更改为 900 之前处于 0x4000000 的原始值或我决定在那里设置的任何值......

int apples = *(int*)(0x4000000);   // lets say that after doing this apples is assigned the value of 10(meaning 10 apples)
   // now how do i backup this original of value 10...
*(int*)(0x4000000) = 900;  // set the apples to 900 and go on... 

不,在你编码之后 apples == 10 和 *(int*)(0x4000000) == 900

如果你做过

int *apples = (int*)(0x4000000);

那么最后*apples会有 900 个。 你可以通过做来保存 10 个

int apples_save = *apples; .

喜欢这个

int *apples = (int*)(0x4000000);
int apples_save = *apples; .
*(int*)(0x4000000) = 900;

现在*apples == 900 和 apples_save == 10 .