Why do we use f/d at the time of initialization of a float
/double
variable in JAVA?
Eg.,
float var1 = 8.56f;
double var2 = 0.87654d;
Will that increase the speed of compilation? Or what maybe the exact reason?
Why do we use f/d at the time of initialization of a float
/double
variable in JAVA?
Eg.,
float var1 = 8.56f;
double var2 = 0.87654d;
Will that increase the speed of compilation? Or what maybe the exact reason?
For doubles and float, you need to specify the compiler the type of the input. Initiailizing 10.0 to a float variable would bring nothing but ambiguity to the compiler, as it would not understand if the value is float or a double.
So by specifying f/d at the end of the value, you're actually removing the ambiguity for the complier by using these format specifiers.