Saturday 16 March 2013

i=i++ * ++i;


void main()
{
clrscr();
int i=5,j=5,k=5;
i=i++ * ++i;
j=++j*++j;
k=k++*k++;

printf("%d\n",i);
printf("%d\n",j);
printf("%d\n",k);

getch();
}
Ans: i=37, j=49, k=27. Postfix increment/decrement have high precedence, but the actual increment or decrement of the operand is delayed (to be accomplished sometime before the statement completes execution). So in the statement y = x * z++; the current value of z is used to evaluate the expression (i.e., z++ evaluates to z) and z only incremented after all else is done.



Blog Author: Vijay Kumar

Go to: Java Aptitude


1 comment: