-
int main()
-
{
-
S s;
-
int *p=&s.i;
-
p[0]=1;
-
p[1]=5;
-
cout<<p[0]<<\" \"<<s.i<<endl;
-
cout<<&p[0]<<\" \"<<&s.i<<endl;
-
cout<<p[1]<<\" \"<<s.p<<endl;
-
cout<<&p[1]<<\" \"<<&s.p<<endl;
-
-
s.p=p;
-
cout<<p[0]<<\" \"<<s.i<<endl;
-
cout<<&p[0]<<\" \"<<&s.i<<endl;
-
cout<<p[1]<<\" \"<<s.p<<endl;
-
cout<<&p[1]<<\" \"<<&s.p<<endl;
-
s.p[1]=1;
-
cout<<s.p<<\" \"<<&s.p<<endl;
-
s.p[0]=2; //s.p指向一个野指针
-
-
return 0;
-
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29012686/viewspace-1146371/
,如需转载,请注明出处,否则将追究法律责任。