C++ Online Compiler
Example: Modulo By Zero in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Modulo By Zero #include <iostream> int main() { // Step 1: Declare a dividend and a zero divisor int a = 10; int b = 0; // Step 2: Attempt modulo operation (this will crash) // int result = a % b; // Uncommenting this line will cause a runtime error // Step 3: Inform the user about the issue std::cout << "Attempting " << a << " % " << b << " will cause a runtime error (division by zero)." << std::endl; // std::cout << a << " % " << b << " = " << result << std::endl; return 0; }
Output
Clear
ADVERTISEMENTS