Showing posts with label sizeof( ). Show all posts
Showing posts with label sizeof( ). Show all posts

Monday, 20 February 2012

Frequently Asked Questions in Technical Round at MNCs like TCS, WIPRO, INFOSYS,..etc – 10

Predict the output or error(s) for the following:


1)

main()

{

char *str1="abcd";


char str2[]="abcd";


printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));


}

Answer:

2 5 5


Explanation:

Sunday, 23 October 2011

Predict the output or error(s) for the following:

main()

{

char *p;


printf("%d %d ",sizeof(*p),sizeof(p));


}

Answer:

1 2

Explanation:

The sizeof() operator gives the number of bytes taken by its operand. P is a character pointer,