0

What type of error it is?

int n = 0/0 ; I tried two compilers. One even didn't noticed it and store '0' in the variable while other displayed it as Runtime error.. Why it is not a syntax error? https://code.sololearn.com/cnBv19TUVuhE/?ref=app

16th Aug 2021, 7:40 AM
Muhammad Hasnain Raza
Muhammad Hasnain Raza - avatar
6 Antworten
+ 2
In C++, division by zero is undefined behavior. So yes, the result varies from compilers. Unless if you divide by 0.0 (float value of zero), you can get either NaN or Infinity and the behavior is defined.
16th Aug 2021, 8:20 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 1
Muhammad Hasnain Raza why do you think so, your syntax is right, then how will it produce a syntax error? When the compiler tried to divides zero by zero, it comes across some weird situations and answers, so based on the implementation of the compiler your using, it'll produce an error, or just give the answer as 0, or whatever. We can't define what the compiler will choose here, and that's why it's called "undefined" case. Understood? I hope you did ;)
17th Aug 2021, 11:24 AM
Rishi
Rishi - avatar
+ 1
Rishi thank you!
17th Aug 2021, 11:28 AM
Muhammad Hasnain Raza
Muhammad Hasnain Raza - avatar
0
What do you expect to be the answer of 0/0?
16th Aug 2021, 2:48 PM
Rishi
Rishi - avatar
- 1
Rishi some kinda syntax error
17th Aug 2021, 11:21 AM
Muhammad Hasnain Raza
Muhammad Hasnain Raza - avatar