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

4th Jun 2020, 3:25 PM
Sourabh Malviya
4 Respuestas
+ 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
4th Jun 2020, 4:43 PM
Sourabh Malviya
+ 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.
4th Jun 2020, 4:39 PM
Gen2oo
Gen2oo - avatar
0
Why do you think || was executed before &&? I think it didn't.
4th Jun 2020, 3:33 PM
Seb TheS
Seb TheS - avatar
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.
4th Jun 2020, 3:42 PM
Seb TheS
Seb TheS - avatar