Are `x = &v` and `*x = v` equivalent?

前端 未结 6 1009
无人共我
无人共我 2020-12-31 10:21
int * x;
int v = 7;

Given this code, what is the difference between 1. x = &v , and 2. *x = v ? I understand that

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-31 10:51

    x = &v modifies x. After the operation x will point to v.

    *x = v modifies the object pointed by x. In the example, x doesn't point at anything because the pointer is uninitialised. As such, the behaviour is undefined.

提交回复
热议问题