字符串问题--C里面的strcpy函数

源代码:

  char s1[]="12345",*s2="123467";
  printf("s1 is:%s\n",s1) ;
  printf("s2 is:%s\n",s2) ;
  printf("s1's strlen:%d\n" ,strlen(s1));
  printf("s1's sizeof:%d\n" ,sizeof(s1));
  printf("s2's strlen:%d\n" ,strlen(s2));
  printf("s2's sizeof:%d\n" ,sizeof(s2));
  printf("strcpy s1 is:%s\n",strcpy(s1,s2)) ;
  printf("strlen %d\n" ,strlen(strcpy(s1,s2)));
  printf("sizeof %d\n" ,sizeof(strcpy(s1,s2))); 
strlen:字符长度

sizeof:1.类型长度2.字符长度+\0的长度也就是strlen+1

[引用]sizeof returns the size counted in bytes, where the C definition of ``byte'' is ``the size of a char.'' In other words, sizeof(char) is always 1. (It turns out that it's not necessarily the case, though, that a byte or a char is 8 bits.)点击打开链接

strcpy:将目的字符串复制给源字符串,并且将字符串覆盖,但是不改变原数组长度

1.遇到\0停止复制 2.如果源空间不够则溢出,并且停止

char s1[]="1234",*s2="123456789";


char s1[]="12345",*s2="1234";


char s1[]="123456\0789",*s2="1234";


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值