How does C++ use signed numbers for mathematical operations
This article introduces the knowledge of "how C++ uses signed numbers for mathematical operations". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
ES.102: use signed numbers for mathematical operations
Reason (reason)
Because most mathematical operations are signed. When x > y, xmury returns a negative number, and in rare cases what is actually required is a modular operation.
Example (sample)
If you don't do it intentionally, unsigned operations can produce unexpected results. If you mix signed and unsigned numbers, the problem will be more obvious.
Template
T subtract (T x, T 2y)
{
Return x-y
}
Void test ()
{
Int s = 5
Unsigned int us = 5
Cout