int main() { int k = 1, j = 2, l=0,o; o = k + j || l++; } 

I went through the debugger, but didn’t understand why the variable о saves the value 1?

Closed due to the fact that the essence of the issue is not clear to the participants of Kromster , MSDN.WhiteKnight , iluxa1810 , nick_n_a , αλεχολυτ 13 Dec '18 at 9:14 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • What does "save" mean? You initially o have no definite value at all. How can she "save" him? - AnT

1 answer 1

The expression (k + j) || (l++) (k + j) || (l++) is a logical expression with the result true . When casting to int type, the value true becomes 1 . You can see it.

The expression has the result true already because to the left of the operator || there is a nonzero value of k + j . Non-zero integer values ​​in a logical context act as true . Since the left operand || is true , then the result is true . Right operand || it will not even be calculated, i.e. l keep the value 0 .

  • This is with parentheses, unless without them || will be executed first +? - dreamIIx