Case 1:
#include <iostream>
int main()
{
double d = 15.50;
std::cout<<(d/0.0)<<std::endl;
}
It compiles without any warnings and prints inf
. OK, C++ can handle division by zero, (see it live).
But,
Case 2:
#include <iostream>
int main()
{
double d = 15.50;
std::cout<<(d/0)<<std::endl;
}
The compiler gives the following warning (see it live):
warning: division by zero [-Wdiv-by-zero]
std::cout<<(d/0)<<std::endl;
Why does the compiler give a warning in the second case?
Is 0 != 0.0
?
Edit:
#include <iostream>
int main()
{
if(0 == 0.0)
std::cout<<"Same"<<std::endl;
else
std::cout<<"Not same"<<std::endl;
}
output:
Same