Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) operator%

 

Operator to obtain the remainder from an integer division.

 

const int three = 7 % 4; //3 is the remainder of 7 divided by 4

 

operator% can often be found in prime determination (in the tool PrimeExpert for example).

 

The code below shows how to determine if a value is odd or even.

 

if (x%2==0)
{
  //x must be even
}
else
{
  //x must be odd
}

 

The STL functor encapsulating operator% is called std::modulus.

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict