Operator evaluation

void main()
{
int x,y=2,z,a;
x=(y*=2)+(z=a=y);
printf(“%d”,x);
}

Tutorial answer:
8
Debugging solution:
Compiler it will evaluate from the right to left but in these case multiplication operator has the higher priority compare to = equivalent operator. so it will evaluate first y*=2:y=y*2,so y become4:
x=y+(z=a=y)now z,a,y values are same so x=4+4=8;

Post a Comment

0 Comments