The program should crash, but it succeeds.

Answered

I divide by zero, but program finished success. I can see error only during debugging. Why I do not see error during run?

1 comment
Comment actions Permalink

Integer division by zero is undefined behavior in C++. What happens may vary by compiler, compiler settings, operating system, processor, and such. It's better not to rely on any particular actual behavior and instead avoid it -- in this case by checking if the divisor is zero and only doing the division if it is non-zero.

The "Arithmetic operators" page on cppreference.com has some discussion in the "Multiplicative operators" section:

https://en.cppreference.com/w/cpp/language/operator_arithmetic

Edit: spelling

0

Please sign in to leave a comment.