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;
}
Why does this code give same answers for sizeof(str2)
and sizeof("abcd")
even when str2
is ideally just like a pointer to a string , as is str1
,so answer should be 4 4 5
Code on Ideone: http://ideone.com/za8aV
Answer: 4 5 5