Saturday, September 22, 2007

TECH OF (9/22)

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

3 comments:

  1. I got the ans as 2 5 5

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Answer:

    2 5 5

    Explanation:

    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.

    ReplyDelete