可以地址被分配给在C变量? [英] Can an address be assigned to a variable in C?
问题描述
是否有可能分配一个变量,你需要的地址,内存中的?
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);
}
什么是错我的做法?
是否有任何C方式中,我们可以将我们想要的地址,给一个变量?
What is wrong with my approach? Is there any way in C in which we can assign an address we want, to a variable?
推荐答案
不能直接。
你可以这样做,但:INT * I = 7200;
..然后我使用(即* I = 10),但你很可能得到一个崩溃。做低层次发展时,这仅仅是有意义的 - 设备驱动程序,等等与已知的内存addreses
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 meaningful when doing low level development - device drivers, etc... with known memory addreses.
这篇关于可以地址被分配给在C变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!