int main()
{
int ar[5]={1,2,3,4,5};
char str1[10]={“hello”};
char str2[10]={‘h’,‘e’,‘l’,‘l’,‘o’};
char str3[]={“hello”};
char str4[]={‘h’,‘e’,‘l’,‘l’,‘o’};
return 0;
}
因为 str1[10]={“hello”} str1[0] = ‘h’
str1[1] = ‘e’
str1[2] = ‘l’
str1[3] = ‘l’
str1[4] = ‘o’
str1[5] = ‘/0’
…
str2[10]={‘h’,‘e’,‘l’,‘l’,‘o’}; str2[0] = ‘h’
str2[1] = ‘e’
str2[2] = ‘l’
str2[3] = ‘l’
str2[4] = ‘o’
str2[5] = ‘0’
…
strlen()到’/0’停止
所以sizeof(str3) 的值是6,strlen(str3) 的值是 5; sizeof(str4) 的值5,
strlen(str4) 没有值
printf("%s “,str3); 可以正确输出;
printf(”%s ",str4); 不可以正确输出 因为没有’/0’
int ar[10] = {};
在sizeof()中表示整个 在其他表示&ar[0]