C - Data Types - Discussion

You Are Here :: Home > C > Data Types - Discussion

 



Q.

main()
{
char *str1="abcd";
char str2[]="abcd";
printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));
}

A. 2 2 2 B. 0 0 0
C. 2 5 5 D. 2 2 5

Answer: Option C
Explaination:

 


In first sizeof, str1 is a character pointer so it gives you the size of the pointer variable. In second sizeof the name str2 indicates the name of the array whose size is 5 (including the '\0' termination character). The third sizeof is similar to the second one.



Discussion

Your Comments Goes here...
NameDiscussion