Answer to Question #44167 in C for nitesh kumar yadav

Question #44167
#‎include‬ <stdio.h>
int main()
{
int x = 0,y = 0, z;
z = ++x || ++y;
printf("%d %d %d",x,y,z);
}
its output will be x=1 y=0, z=1.
how it is print y=0? give me reason please
1
Expert's answer
2014-07-15T11:07:50-0400
#include <stdio.h>
int main()
{
int x = 0, y = 0, z;
z = ++x || ++y;
printf("%d %d %d", x, y, z);
}
Yes, its output will be x=1, y=0, z=1. This happens because of optimisation: when "z = ++x || ++y;" is processed, x is being incremented and the entire expression is TRUE. As there is logical OR in this expression, further elements will be ignored for optimisation purposes.
You could also try to exchange the order: "z = ++y || ++x;", and ypu'll get the following result: x=0, y=1, z=1 - as you can see, same thing occured and x isn't incremented.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS