字符串 \0 的重要性
作者:互联网
int main() {
char arr[] = { "hello world" };
char arr1[] = { 'h','e','l','l','o' };
char arr2[] = { 'h','e','l','l','o','\0'};
printf("%s\n", arr);//hello world
printf("%s\n", arr1);//hello烫烫烫烫烫烫烫烫烫烫烫烫烫蘦ello
printf("%s\n", arr2);//hello
printf("%d\n", strlen(arr));//11
printf("%d\n", strlen(arr1));//报错
printf("%d\n", strlen(arr2));//5
return 0;
}
//因为arr1数组中没有\0所有程序会一直查找直到找到\0后才会停下来
//所以会报错
标签:arr,重要性,烫烫,char,arr1,printf,字符串,hello 来源: https://www.cnblogs.com/meng-chen/p/16029878.html