int main(){char *str1 = \"http://see.xidian.edu.cn/cpp/u/shipin/\";
char str2[100] = \"http://see.xidian.edu.cn/cpp/u/shipin_liming/\"; char str3[5] = \"12345\";
printf(\"strlen(str1)=%d, sizeof(str1)=%d\\n\ printf(\"strlen(str2)=%d, sizeof(str2)=%d\\n\ printf(\"strlen(str3)=%d, sizeof(str3)=%d\\n\ return 0;}
运⾏结果:
strlen(str1)=38, sizeof(str1)=4strlen(str1)=45, sizeof(str1)=100strlen(str1)=53, sizeof(str1)=5
如果字符的个数等于字符数组的⼤⼩,那么strlen()的返回值就⽆法确定了,例如
char str[6] = \"abcxyz\";
strlen(str)的返回值将是不确定的。因为str的结尾不是0,strlen()会继续向后检索,直到遇到'\\0',⽽这些区域的内容是不确定的。