Can an address be assigned to a variable in C?

前端 未结 9 2133
孤城傲影
孤城傲影 2021-01-06 05:28

Is it possible to assign a variable the address you want, in the memory?

I tried to do so but I am getting an error as \"Lvalue required as left operand of assignmen

9条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-06 05:59

    It's not possible, maybe possible with compiler extensions. You could however access memory at an address you want (if the address is accessible to your process):

    int addr = 7200;
    *((int*)addr) = newVal;
    

提交回复
热议问题