Assigning int value to an address

后端 未结 6 1420
一向
一向 2021-01-15 20:06

I thought the following codes were correct but it is not working.

int x, *ra;     
&ra  = x;

and

int x, ra;
&ra = x         


        
6条回答
  •  隐瞒了意图╮
    2021-01-15 20:31

    Both of those causes, in the way you have them in your question, undefined behavior.

    For the first, you don't initialize the pointer, meaning it points to a random location (or NULL if the variable is global).

    For the second, you try to change the address the variable is located at, which (if it even would compile) is not allowed.

提交回复
热议问题