What does the ">" operator do in the middle of an arithmetic expression in C++?

Asked

Viewed 97 times

4

I found this line of code in a proposed solution to a certain problem.

excedente = a % 10 + b % 10 + excedente > 9;

My point is, what function is that the > 9 makes this line me specific?

1 answer

10


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, either the result will be false or true, it cannot be anything else, therefore the variable excedente is the type bool and will have the value false or the value true.

Note that the expression on the left is every mathematical operation a % 10 + b % 10 + excedente, since the precedence of this operator is lower than the other operators used, and has associations from left to right, so we can read this way:

excedente = ((a % 10 + b % 10 + excedente) > 9);

I put in the Github for future reference.

And of course, he wants to know if that left calculus is bigger than 9.

  • I have never seen such an example. Thank you !

  • Extremely common.

  • I’m still learning C++. All help is essential.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.