C++strcpy内存覆盖问题


点击(此处)折叠或打开

  1. char str[]=\"123456789\";
  2. char dst[]=\"aaa\";
  3. strcpy(dst, str);
  4. cout<<str<<endl;
  5. cout<<dst<<endl;
  6. cout<<&str<<endl;
  7. cout<<&dst<<endl;
  8. 因为dst和str内存相连 所以str复制到dst时 把自己给覆盖了


Cqq83wAAAAASUVORK5CYII=



点击(此处)折叠或打开

  1. char str[10]=\"123456789\";
  2. char dst[10]=\"aaa\";
  3. strcpy(dst, str);
  4. cout<<str<<endl;
  5. cout<<dst<<endl;
  6. cout<<&str<<endl;
  7. cout<<&dst<<endl;



点击(此处)折叠或打开

  1.     char dst[]=\"aaa\";
  2.     char str[]=\"123456789\";
  3.     char *p13=(char *)0x0012FF44;
  4.     char *p12=(char *)0x0012FF43;
  5.     char *p11=(char *)0x0012FF42;
  6.     char *p10=(char *)0x0012FF41;
  7.     char *p9=(char *)0x0012FF40;
  8.     char *p=(char *)0x0012FF3F;
  9.     char *p1=(char *)0x0012FF3F;
  10.     char *p2=(char *)0x0012FF3E;
  11.     char *p3=(char *)0x0012FF3D;
  12.     char *p4=(char *)0x0012FF3C;
  13.     char *p5=(char *)0x0012FF3B;
  14.     char *p6=(char *)0x0012FF3A;
  15.     char *p7=(char *)0x0012FF39;
  16.     char *p8=(char *)0x0012FF38;
  17.     cout<<*p13<<endl;
  18.     cout<<*p12<<endl;
  19.     cout<<*p11<<endl;
  20.     cout<<*p10<<endl;
  21.     cout<<*p9<<endl;
  22.     cout<<*p<<endl;
  23.     cout<<*p1<<endl;
  24.     cout<<*p2<<endl;
  25.     cout<<*p3<<endl;
  26.     cout<<*p4<<endl;
  27.     cout<<*p5<<endl;
  28.     cout<<*p6<<endl;
  29.     cout<<*p7<<endl;
  30.     cout<<*p8<<endl;
  31.     cout<<&dst<<endl;
  32.     cout<<&str<<endl;

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

转载于:http://blog.itpub.net/29012686/viewspace-1141720/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值