The program should crash, but it succeeds.


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 has some discussion in the "Multiplicative operators" section:

Edit: spelling


Please sign in to leave a comment.