指针赋值有顺序吗
一个面试题目:typedef struct S{
int i;
int * p;
}S;
int main(void)
{ struct S s;
int * v = &s.i;
v[0] = 4;
v[1] = 3;
s.p = &s.i;
s.p[1] = 1;
s.p[0] = 2;
return 0;
}
运行到s.p[0] = 2;处会崩溃,但如果把s.p[0] = 2;放在s.p[1] = 1;上面,则正常通过。why? 指针赋值是否有顺序?请指教,谢谢