What is the output of this C code?
void main()
{
int a = 5, b = -7, c = 0, d;
d = ++a && ++b || ++c;
printf("\n%d%d%d%d", a, b, c, d);
}
Answer: D
Correct answer: 6 -6 0 1
Evaluate left to right, remembering that any non-zero value is true.
++amakesa6, which is true.++bmakesb-6 - non-zero, so also true.- The
&&is therefore true, so||short-circuits and++cnever runs:cstays 0. dgets the value of the whole expression, 1.
Output: 6 -6 0 1.
Please log in or register to report this question.