+ 3
What does this symbol mean? ==
I've seen in duel this symbol ==, but it was in an equation like that '<< cout << (a+(b==c))'. I can't understand what is the function of this one. I've seen this symbol before in manual, for example: 'if (a==c)'. And i understand, that they both have different functions. What does this symbol mean in such an equation '(a+(b==c))'? P.S. #sry4myenglish
7 Answers
+ 5
Poorie
For a + (b == c), the result is a or a + 1 depending on whether b == c is true or false (2 == 4 would be false, resulting in 0, resulting in the final answer being a, while 3 == 3 would be true, resulting in 1, resulting in the final answer being a + 1). So:
x = 2 + (3 == 3) -> x = 2 + true -> x = 2 + 1 -> x = 3
x = 2 + (3 == 1) -> x = 2 + false -> x = 2 + 0 -> x = 2
Besides ==, you can also use other conditional operators, like !=, >, <, etc.
For the a + (b == c) * (d / e) expression, you are correct. It could be a in the case that b == c is false, resulting in a + 0 * (d / e), which is just a. It could also be a + (d / e) in the case that b == c is true, resulting in a + 1 * (d / e), which is just a + (d / e).
Hope that helps! :)
+ 3
The expression b == c evaluates to either 0 (false), 1 (true), or an error occurs. With that in mind, you can add another integer (or something else), perhaps integer a.
:)
+ 3
false: 0
true: 1
So you can use conditions in calculations like +-*/%.
+ 2
Just to add to Lunar Coffee's excellent answer, here is some code to help you learn:
https://code.sololearn.com/ch3scU0mcxh6/#c
Also, I think you meant 'a+(b==c)+(d/e)' rather than 'a+(b==c)*(d/e)'?
+ 1
LunarCoffee
Thank you for your answer.
I hope, that i understood right. It means, that for example in this equation 'a+(b==c)' the answer is 'a'?
And what about the equation, for example 'a+(b==c)*(d/e)'? The answer is again 'a' or 'a+(d/e)'.
Jesus, it's quite hard.
+ 1
LunarCoffee
Jesus, you are god! Now i understand it, like a black word on the white list! You are the best!
+ 1
it is the comparison operator "is equal to" which returns true (which has the value 1) or false (which has the value of 0). in the equation given, a would be incremented by one only if b and c are equal,