So for two separate code fragments, why does an incrementor/decrementor act differently?
Fragment A:
i=7; j=8; k=9;
printf("%d\n", i - 7 && j++ > k);
printf("%d %d %d", i, j, k);
will produce the following output:
0
7 8 9
Fragment B:
while (i > 0)
printf("T minus %d and counting\n",i--);
produces this:
T minus 5 and counting
T minus 4 and counting
T minus 3 and counting
T minus 2 and counting
T minus 1 and counting
Now, I know that arguments to functions are passed by value, and that it must have something to do with the fact that j is used in a boolean expression. But these two situations seem contradictory to me. What’s going on here?
Okay, you’re going to need to look very closely at how the operators precedences are arranged and exactly how they work. Since this is homework, i’m not going to give the exact answer, but there are two things you should do.
&&. In particular, when is the subexpressionj++ > kexecuted?