<分区>
Possible Duplicate:
Question about pointers and strings in C
#include<stdio.h>
int main()
{
char *str1="abcd";
char str2[]="abcd";
printf("%d %d %d\n",sizeof(str1),sizeof(str2),sizeof("abcd"));
return 0;
}
为什么这段代码对 sizeof(str2)
和 sizeof("abcd")
给出了相同的答案,即使 str2
非常理想一个指向字符串的指针,如 str1
,所以答案应该是 4 4 5
Ideone 上的代码: http://ideone.com/za8aV
答案:4 5 5