I found this line of code in a proposed solution to a certain problem.
excedente = a % 10 + b % 10 + excedente > 9;
My question is, what is the role of > 9
in this specific line?
I found this line of code in a proposed solution to a certain problem.
excedente = a % 10 + b % 10 + excedente > 9;
My question is, what is the role of > 9
in this specific line?
This is the relational operator of "greater than", equal to what it has in mathematics, so it compares the operand that is on the left with the operand that is on the right and results in a Boolean value, that is, or the result it will be false or true, it can not be anything else, so the variable excedente
is of type bool
and will have the value false
or the value true
.
Note that the expression on the left is any mathematical operation a % 10 + b % 10 + excedente
, since the precedence of this operator is smaller than the other operators used, and has left-to-right associativity, so we can read:
excedente = ((a % 10 + b % 10 + excedente) > 9);
Of course, he wants to know if that calculation on the left is greater than 9.