+ 1
No run-time error for division by zero in c++ in mac?
Hi, in c++ on a mac, I noticed that when I do a division by zero I don't get any run-time error and the program executes, but just skipping the output of such division. I have codelite 14.0.1 and using gcc as a compiler. Is this behavior expected? Thanks!
1 Resposta
+ 2
According to the C++ standard, division by zero falls under undefined behaviour, which means basically anything might happen, so there isn't really any behaviour to expect beforehand. In practice, it will also depend on the types used, since floating point numbers are way stricter standardized than integers. For a more detailed explanation, see the following thread:
https://www.quora.com/What-happens-if-we-divide-by-0-in-C
Or this similar thread:
https://www.quora.com/Why-does-division-by-zero-return-INF-infinite-with-floats-but-makes-the-program-crash-with-integers-in-C++