Skip to content

Latest commit

 

History

History
29 lines (21 loc) · 654 Bytes

CppIsOdd.md

File metadata and controls

29 lines (21 loc) · 654 Bytes

IsOdd is a check code snippet to determine if an int is odd.

bool IsOdd(const int i) noexcept
{
  return i % 2 != 0;
}

Broken oddness check

Below is an example of an IsOdd implementation, that has a broken oddness check:

//Don't: broken oddness check
bool IsOdd(const int i) noexcept
{
  return i % 2 == 1; //Broken oddness check!
}

This implementation is broken, as it will not work for negative integers.

External links