0
#include<stdio.h> int main() { int i=-3, j=2, k=0, m; m = ++i || ++j && ++k; printf("%d, %d, %d, %d\n", i, j, k, m);
Why &&. Precedence is high but why here || is first execute
4 Réponses
+ 1
Hey I understand this code according to operater precedence first is increament is executed so ++I first execute. Than || operator is rule when any one condition is true in || so after code is not execute becouse it always true. So correct ans is I=-2,j=2,k=1,M=1
+ 2
The logical AND has a higher precedence (as you said) so it will be read this way:
m = ++i || (++j && ++k);
The logical OR short-circuits after the first statement evaluates to true, so the second statement is never evaluated.
0
Why do you think || was executed before &&? I think it didn't.
0
I assume you to be confused about why m ended to store 1 instead of -2.
In C, logical operators can only return 0 or 1, unlike in high-level programming languages, such as Python where either operand is returned instead.