如何在C中写入特定地址的数据

vku*_*rni 3 c c++

我需要在地址0x8000000中写入0x00001234,是否可以在C?

Ser*_*rgV 12

如果您在嵌入式系统中使用硬件寄存器,那么标准方法是:

int volatile * const p_reg = (int *) 0x8000000;
*p_reg = 0x1234;
Run Code Online (Sandbox Code Playgroud)

如果省略volatile,那么优化编译器会遇到很多问题


Tho*_*uiz 9

你可以,但你会有99.9999..9%的段错误,因为你的程序将无法访问这个内存地址.

int *nb = (int *) 0x8000000;
*nb = 0x00001234;
Run Code Online (Sandbox Code Playgroud)