Follow Me on Twitter

Sunday, October 25, 2009

Solutions to C Puzzles

I will be posting solution to the questions posted on http://www.gowrikumar.com/ site.

1)
What is the output of the following program?
#include 
int main()
{
int i;
i = 10;
printf("i : %d\n",i);
printf("sizeof(i++) is: %d\n",sizeof(i++));
printf("i : %d\n",i);
return 0;
}


Solution:

10
4
10

Reason the value of i at the second printf is still 10 is because
operation performed inside the sizeof operator doesn't change the
value of i.

The 'sizeof' operator is used to determine the amount of space any
data-element/datatype occupies in memory

No comments:

Post a Comment