+ 2

Can you explain the output of this particular code ?

Explain the output https://code.sololearn.com/co1d1xru90P8/?ref=app

10th Apr 2022, 1:11 AM
Jogender Singh
1 Antwort
+ 8
int a =1; int b =1; int c = a || --b; The C language does short-circuit logic evaluation. Since a is non-zero, it skips evaluating --b. The expression evaluates to true, which gets stored as 1 in c. It leaves b as 1. int d = a-- && --b; Since a is 1, the left operand is seen as true. Then a gets decremented to 0. Now it must evaluate the right operand. First, b gets decremented from 1 to 0. Since the right operand is 0 (false) the whole expression evaluates to false, and 0 gets stored in d. Now a=0, b=0, c=1, d=0.
10th Apr 2022, 2:18 AM
Brian
Brian - avatar