From ISO14882:2011(e) 5.6-4:
The binary / operator yields the quotient, and the binary % operator yields the remainder from the division of the first expression by the second. If the second operand of / or % is zero the behavior is undefined. For integral operands the / operator yields the algebraic quotient with any fractional part discarded; if the quotient a/b is representable in the type of the result, (a/b)*b + a%b is equal to a.
The rest is basic math:
(-7/3) => -2 -2 * 3 => -6 so a%b => -1 (7/-3) => -2 -2 * -3 => 6 so a%b => 1
Note that
If both operands are nonnegative then the remainder is nonnegative; if not, the sign of the remainder is implementation-defined.
from ISO14882:2003(e) is no longer present in ISO14882:2011(e)
Related Posts:
- How to create a dynamic array of integers
- How to implement 2D vector array?
- What is the difference between g++ and gcc?
- What is the best way to use a HashMap in C++?
- What is the difference between float and double?
- How do I find the length of an array?
- C++ — expected primary-expression before ‘ ‘
- Using getline() with file input in C++
- Making my own toString() method on c++ struct
- Struct Constructor in C++?
- What is meant with “const” at end of function declaration? [duplicate]
- What’s the C++ version of Java’s ArrayList
- What is the difference between “long”, “long long”, “long int”, and “long long int” in C++?
- ‘g++’ is not recognized as an internal or external command, operable program or batch file
- How do I convert a double into a string in C++?
- How to create timer events using C++ 11?
- How to concatenate two strings in C++?
- ‘g++’ is not recognized as an internal or external command, operable program or batch file
- Read file line by line using ifstream in C++
- Virtual/pure virtual explained
- error: redefinition of class
- Officially, what is typename for?
- How do I iterate over the words of a string?
- What does T&& (double ampersand) mean in C++11?
- C++ – No matching member function for call to ‘push_back’
- error: lvalue required as unary & operand
- C/C++ JSON parser
- C++ Parsing input string to variables
- ‘cout’ was not declared in this scope
- Segmentation fault error 11 C++
- Why doesn’t C++ have a garbage collector?
- How does ifstream’s eof() work?
- terminate called after throwing an instance of ‘std::invalid_argument’ what(): stoi
- How to find memory leak in a C++ code/project?
- invalid use of non-static member function
- Visual Studio debugger error: Unable to start program Specified file cannot be found
- Printing the correct number of decimal points with cout
- libstdc++-6.dll not found
- vector
::size_type in C++ - What does ‘\0’ mean?
- cin >> “no operator matches these operands”
- C++ on mac : linker command failed with exit code 1 (use -v to see invocation)
- Correct way to use cin.fail()
- Destructor for a linked List
- Why use a new call with a C++ ‘vector’?
- Identifier is undefined
- What are the most widely used C++ vector/matrix math/linear algebra libraries, and their cost and benefit tradeoffs?
- Arduino sprintf float not formatting
- How to end C++ code
- Delete 2D array C++
- class not declared in scope – even though .h was included
- Best C/C++ Network Library
- How to check that an element is in a std::set?
- Best way to extract a subvector from a vector?
- How do malloc() and free() work?
- Call to implicitly deleted copy constructor in LLVM
- QltAW.png
- std::wstring VS std::string
- C++ string to enum
- c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)
- why is string not declared in scope
- How does rhs work?
- error: expected unqualified-id before ‘.’ token //(struct)
- Base class undefined
- C++ – Assigning null to a std::string
- The program can’t start because libgcc_s_dw2-1.dll is missing
- C++ – Too Many Initializers for Arrays
- Reading string by char till end of line C/C++
- How do I flush the cin buffer?
- C++ Return value, reference, const reference
- G++ undefined reference to class::function
- Is string::compare reliable to determine alphabetical order?
- How to return a struct from a function in C++?
- C++ printing boolean, what is displayed?
- Error : aggregate ‘first one’ has incomplete type and cannot be defined
- CMake : C and CXX compiler identification is unknown Win10 CMakeGUI
- Error “Unterminated conditional directive” in cross-referencing headers
- C++ template – error: expected initializer before ‘<' token
- how to destroy an object in C++
- Error in assignment of member in read-only object
- creating an array of structs in c++
- What’s the Use of ‘\r’ escape sequence?
- How do I use an enum value in a switch statement in C++?
- Why should I use a pointer rather than the object itself?
- Call of overloaded function is ambiguous
- ‘cout’ does not name a type
- C++ Cannot call constructor directly in small example
- C++ compiler error c4430 “c++ doesnt support default int”
- Using OpenMP with clang
- Using cin for char array
- invalid use of ‘this’ outside of a non-static member function error?
- Dev C++ compilation error, permission denied
- Why do I get: -9223372036854775808
- Return a 2d array from a function
- Linker error: “linker input file unused because linking not done”, undefined reference to a function in that file
- What is the difference among ios::app, out, and trunc in c++?
- Where can I find ‘winmm.lib’ (I’m using Visual Studio 2012)
- What is a `char*`?
- Does static constexpr variable inside a function make sense?
- “Incomplete type not allowed ” when creating std::ofstream objects