Wednesday, March 24, 2010

69

int main()
{
int i=0,j;
j=(i++,++i);
printf("%d %d ",i,j);
return 0;
}

Output

 2  2 

Logic:
As per the Associativity of the brackets ,j=++i(brackets associativity is left to right).The statements is equal to i++,j=++i;

These statements will executed like this:

line 1:     i++,         //'i' is equal to 1.
line 2:     j=++i;         //j=++i(preincrement) so j=2 and i=2



','(comma)operator is used to group one or more statements.

0 comments:

Post a Comment