What will be the outout of the following code?
#include <stdio.h> int main() { int a = 1, b = 2; int c = a++ || b++; printf("%d %d %d", a, b, c); }
int a = 1, b = 2; int c = a++ || b++;
2nd statement will run a++ and then there is logical OR operator so it will halt. (Short Circuit Rule for logical operators in C).
c = 1, a = 2, b = 2 (unaffected)
int c = a++ || b++;
The logical OR would stop as soon as it finds any positive value ($\equiv$ 1). It stops right at a.
So, c = a
=> c = 1
Now, a++
=> a = 2
And b is never touched.
So, 2,2,1.
Option C
64.3k questions
77.9k answers
244k comments
80.0k users