I've only ever seen "==" being used inside an if statement. So how does "==" work in this context?
a = 5;
b = (a == 18 % 13);
If b
is a bool
, you can assign the result of an expression to it. In this case, if the condition a == 18 % 13
holds, b
will become true
, otherwise false
.
Basically,
a == 18 % 13 - would yield b = true or b = 1
and
a != 18 % 13 - would yield b = false or b = 0
depending on the type of b
.
This
a == 18 % 3
is equivalent to
a == (18%3)
since the modulus operator %
has higher precedence than the equality operator ==
.
This expression evaluates to true
or false
(actually, true
in this case). So you are assigning the result of that to variable b
. b
itself could be a bool
or anything that can be converted from bool
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With