0
What will be the output of the C code
#include <stdio.h> void main() { int x = 1, y = 0, z = 5; int a = x && y || z++; printf("%d", z); }
5 Antworten
+ 10
Try it on Sololearn Playground.
+ 6
In C, order of evaluation of operands is defined for && and || operator(it is from Left to Right), also this expression will be evaluated from L to R with no short-circuit. You need to evaluate z++ to get value of a so z get incremented by 1.
((x&&y)||(z++)) shows the precedence
-> (x&&y) : x 1st, y 2nd (order of evaluation)
-> since its 0, we need 2nd expression z++ to get final value
-> z++
+ 4
~ swim ~
Correct, && have more precedence than ||
I will correct it, thanks for pointing out this mistake.