源代码:
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";