0

I know that double has more precision than float and all that, but during lecture, my professor said 0.5 is a double. Could it be float too?

short int s;
int i;
long int l;
float f;
double d;
l = 2 * s + i * f - 0.5 * d;
Soso Wang
  • 9
  • 3

1 Answers1

0

According to this SO question, the type of a floating point literal (i.e. a number with a decimal point in it) is by default double unless it has a suffix of f:

The type of a floating literal is double unless explicitly specified by a suffix. The suffixes f and F specify float, the suffixes l and L specify long double.

So, your professor appears to be spot on. In the above expression 0.5 will be treated like a double by default. I hope that you will get a high grade on the final exam.

Community
  • 1
  • 1
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360