Initialization of float can be done as follows,
float a = 0.0
float a = 0.f
float a = float(0)
Is there any pros and cons to use any of these?
Initialization of float can be done as follows,
float a = 0.0
float a = 0.f
float a = float(0)
Is there any pros and cons to use any of these?
It doesn't matter at all. You could also say float a = 0;
and again it would be the same thing. Or float a = float();
. I think the most conventional would be 0
, 0.0
, or 0f
; the rest are just redundant.
The first initializes from a double literal, whereas the second is from a float literal. The bits in the two zeros may not be the same.
The third is c++ constructor-like syntax that actually just does direct initialization, in this case from an integer literal.