Alex Rivera | Logout

C++ difference between 0 and 0.0

Asked 2009-09-05T22:44:21.060
21

Is there a difference between 0 and 0.0 in C++? Which should you use for initializing a double?

Thanks

Edit
Report

1 Answer

13

I try to keep my constants type-consistent. 0 for ints. 0.0f or 0.f for float, and 0.0 for double.

To me, the most important reason to do this is so the compiler and the programmer see the same thing.

If I do this...

float t=0.5f;
float r;

r= 1 * t;

...should r be assigned 0 or .5? There's no hesitation if I do this instead...

float t=0.5f;
float r;

r= 1.0f * t;
answered 2009-09-05T23:01:31.703

Your Answer