What's the use of suffix `f` on float value

3.00 is interpreted as a double, as opposed to 3.00f which is seen by the compiler as a float.

The f suffix simply tells the compiler which is a float and which is a double.

See MSDN (C++)


In addition to what has already been said, keeping track of 1.0 versus 1.0f is more important than many people realize. If you write code like this:

float x;
...
float y = x * 2.0;

Then x will be promoted to a double, because 2.0 is a double. The compiler is not allowed to optimize that promotion away or it would violate the C standard. The calculation takes place with double precision, and then the result is then implicitly truncated into a float. This means that the calculation will be slower (though more accurate) than it would have been if you had written 2.0f or 2.

Had you written 2, the constant would be of int type, which would be promoted to a float, and the calculation would have been done with "float precision". A good compiler would warn you about this promotion.

Read more about the "usual arithmetic conversion" rules here:

http://msdn.microsoft.com/en-us/library/3t4w2bkb%28v=vs.80%29.aspx


Because by unsuffixed floating-point literals are doubles, and rounding means that even small literals can take on different values when rounded to float and double. This can be observed in the following example:

float f=0.67;
if(f == 0.67) 
  printf("yes");
else 
  printf("no");  

This will output no, because 0.67 has a different value when rounded to float than it does when rounded to double. On the other hand:

float f=0.67;
if(f == 0.67f) 
  printf("yes");
else 
  printf("no"); 

outputs yes.

The suffix can be specified using either upper or lowercase letters.

Try this also:

printf(" %u %u\n", sizeof(.67f), sizeof(.67));

Check @codepade