-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy path4.35.txt
28 lines (23 loc) · 1021 Bytes
/
4.35.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Exercise 4.35: Given the following definitions,
char cval;
int ival;
unsigned int ui;
float fval;
double dval;
identify the implicit type conversions, if any, taking place:
(a) cval = 'a' + 3;
(b) fval = ui - ival * 1.0;
(c) dval = ui * fval;
(d) cval = ival + fval + dval;
By Faisal Saadatmand
(a) a is converted to int, added to 3 and the result is converted to char (truncated).
(b) ival is converted to a double. To evaluate the result of the subtraction
the conversion is implementation dependent, i.e.: depends on the size of
unsigned and double. The result of the assignment operator is a conversion to a
float--possible loss of precision.
(c) Conversion depends on the size of unsigned int and float. Result of
the assignment is converted to a double.
(d) ival is converted to float, added to fval. The result of the addition is
converted to a double and added to dval. The final result is converted to
int, which results in a loss of precision, and then to char, which
truncates the value.