I need help understanding how the expression below should be interepted, because I have no clue. help please.
Expression: 11U/22L*(3.75F-2)+3./6+.25/1.F;
Choices:
A) 0.5 B) 0.25
C) 0.0 D) 0.75
I need help understanding how the expression below should be interepted, because I have no clue. help please.
Expression: 11U/22L*(3.75F-2)+3./6+.25/1.F;
Choices:
A) 0.5 B) 0.25
C) 0.0 D) 0.75
U: unsigned int
L: long int
F: float
integral literal: [signed] int
FP literal (without suffix f/F): double
11U / 22L * (3.75F - 2) + 3. / 6 + .25 / 1.F
-> unsigned / long * (float - int) + double / int + double / float
Now, we need an understanding of operator precedence and type promotion (conversion).
Then the expression evaluates to:
unsigned / long -> promoted to long
*
(float - int) -> promoted to float
+
double / int -> promoted to double
+
double / float -> promoted to double
Put the values in:
11U / 22L -> 0L
*
(3.75F - 2) -> 1.75F
+
3. / 6 -> 0.5
+
.25 / 1.F -> 0.25
=> 0L * 1.75F + 0.5 + 0.25
=> 0F + 0.5 + 0.25
=> 0.5 + 0.25
=> (double) 0.75