函数strlen()和sizeof的区别: #include<stdio.h> #include<stdlib.h> #include<string.h> #define SENTENCE "It is a cat" int main() { char name[40]; gets(name); printf("%s\n", name); printf("The size of name is %zd %d\nThe s…
strlen表示的实际的字符串长度,不会把字符串结束符'\0'计算进去,而sizeof则不是实际的字符串长度,它会把字符串的结束标识符'\0'也包含进去. #include<stdio.h> int main() { char cdata1[125]="hello"; int len1=strlen(cdata1); char cdata2[]="hello"; int len2=strlen(cdata2); printf("cdata1实际…