I know that similar questions are already posted many times here and I searched with Google and here and read answers to those questions, but there is something not clear to me and here it is:
float x = 1.5;
float z = 0.0;
z = x + 5.22f;
Here I am convinced that it is necessary to add f
after the number 5.22 so that the compiler won't treat it as double
.
The point is in the book I am reading the author do this:
float myvar = 2.55f;
My question is: I already declared "myvar" to be float
what is the purpose of the f
suffix? Why the repetition?
Is it possible that the compiler treats the value 2.55 as a double
and when it tries to assign it to myvar
it demotes it to float
, so the purpose of the f
is to prevent this?