ITPub博客

首页 > 应用开发 > IT综合 > C++指针转换

C++指针转换

原创 IT综合 作者:dongyu2013 时间:2014-04-21 19:16:37 0 删除 编辑

点击(此处)折叠或打开

  1. int main()
  2. {
  3.     S s;
  4.     int *p=&s.i;
  5.     p[0]=1;
  6.     p[1]=5;
  7.     cout<<p[0]<<\" \"<<s.i<<endl;
  8.     cout<<&p[0]<<\" \"<<&s.i<<endl;
  9.     cout<<p[1]<<\" \"<<s.p<<endl;
  10.     cout<<&p[1]<<\" \"<<&s.p<<endl;

  11.     s.p=p;
  12.     cout<<p[0]<<\" \"<<s.i<<endl;
  13.     cout<<&p[0]<<\" \"<<&s.i<<endl;
  14.     cout<<p[1]<<\" \"<<s.p<<endl;
  15.     cout<<&p[1]<<\" \"<<&s.p<<endl;
  16.     s.p[1]=1;
  17.     cout<<s.p<<\" \"<<&s.p<<endl;
  18.     s.p[0]=2; //s.p指向一个野指针

  19.     return 0;
  20. }

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29012686/viewspace-1146371/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: C++指针问题
下一篇: sleep和wait的区别
请登录后发表评论 登录
全部评论

注册时间:2013-12-25

  • 博文量
    263
  • 访问量
    238063