Answer the question
In order to leave comments, you need to log in
Why doesn't prefix increment in boolean expression add one after evaluation?
int i, l, j, k;
i = l = j = k = 0;
int a = i++ && ++j || k || l++;
i = 1 l = 1 j = 1 k = 0 a = 0
i = 1 l = 1 j = 0 k = 0 a = 0
Answer the question
In order to leave comments, you need to log in
Because i++ == 0 which translates to false. So the second term of the conjunction (++j) makes no sense to calculate, the result does not depend on it. The first term of the disjunction is false, so we calculate the second one (k == 0). It is also false, so we evaluate the third one (l++) and take its value as the result of the expression.
In general, conjunction (&&) evaluates to the first false encountered, disjunction (||) evaluates to the first true encountered.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question