[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppModulusOperator
This is very handy to, for example, determine if a number is odd or even:
There is also a STL functors called std::modulus.
The five mathematical operators are:
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppModulusOperator
(C++) % operator
The modulus/modulo operator is used to get the remainder of a division of two integer values.const int three = 7 % 4;
This is very handy to, for example, determine if a number is odd or even:
if (x%2==0)
{
//x is even
}
else
{
//x is odd
}
There is also a STL functors called std::modulus.
The five mathematical operators are:
- +, plus operator
- -, minus operator
- *, multiply operator
- /, divide operator
- %, modulus operator
'Modulus operator' links
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
