Read and write to a memory location

前端 未结 9 1235
忘掉有多难
忘掉有多难 2021-01-05 05:40

After doing lot of research in Google, I found below program

#include 

int main()
{
    int val;
    char *a = (char*) 0x1000;
          


        
9条回答
  •  有刺的猬
    2021-01-05 06:05

    You can't just write at any random address. You can only modify the contents of memory where your program can write.

    If you need to modify contents of some variable, thats why pointers are for.

    char a = 'x';
    char* ptr = &a; // stored at some 0x....
    *ptr = 'b'; // you just wrote at 0x....
    

提交回复
热议问题