How can I logically understand this:
int low_digit = value % 10;
value /= 10;
Where I am lost is when mod divides and print the remainder. What is it dividing by?
What does value /= 10; mean?
/= is the C++ way of saying:
value = value / 10;
Here value % 10 gives you the reminder of dividing it by 10. Imagine value is 19, this will give you 9, the last digit (reminder of dividing it by 10). The last statement, will divide that value by 10 (integer division), and will give you 1 (the tens digit).
This is an assignment shorthand and a more efficient way of saying:
value = value / 10;
Just like:
i++;
is:
i = i + 1;
or:
i +=1;
You could also do:
value %= 10; // same as value = value % 10;
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