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
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.
+ 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 ;)
+ 1
Rishi thank you!
0
What do you expect to be the answer of 0/0?
- 1
Rishi some kinda syntax error