address-operator

Can an address be assigned to a variable in C?

六月ゝ 毕业季﹏ 提交于 2019-11-30 18:17:16
问题 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 assignment". int main() { int i = 10; &i = 7200; printf("i=%d address=%u", i, &i); } What is wrong with my approach? Is there any way in C in which we can assign an address we want, to a variable? 回答1: Not directly. You can do this though : int* i = 7200; .. and then use i (ie. *i = 10) but you will most likely get a crash. This is only