Azka - 05 Qs
Azka - 05 Qs
ENGR1301 – A
2021 Spring Semester
05 Types - Tutorial Questions
a) 07
7 x 8^0 = 7
b) 077
(7 x 8^1) + (7 x 8^0) = 56 + 7 = 63
c) 0777
(7 x 8^2) + (7 x 8^1) + (7 x 8^0) = 511
a) 0x123
(1 x 16^2) + (2 x 16^1) +(3 x 16^0) = 291
b) 0x321
(3 x 16^2) + (2 x 16^1) +(1 x 16^0) = 801
c) 0XABC
(10 x 16^2) + (11 x 16^1) +(12 x 16^0) = 2748
d) 0XCBA
(12 x 16^2) + (11 x 16^1) +(10 x 16^0) = 3258
a) 07
7 x 8^0 = 7
7 : 16 = 0 | R = 7
= 7
b) 077
(7 x 8^1) + (7 x 8^0) = 56 + 7 = 63
63 : 16 = 3 | R = 15 (F)
3 : 16 = 0 | R = 3
= 3F
c) 0777
(7 x 8^2) + (7 x 8^1) + (7 x 8^0) = 511
511 : 16 = 31 | R = 15 (F)
31 : 16 = 1 | R = 15 (F)
1 : 15 = 0 | R = 1
= 1FF
= 443
b) 0x321
(3 x 16^2) + (2 x 16^1) +(1 x 16^0) = 801
801 : 8 = 100 | R = 1
100 : 8 = 12 | R = 4
12 : 8 = 1 | R = 4
1 : 8 = 0 | R = 1
= 1441
c) 0XABC
(10 x 16^2) + (11 x 16^1) +(12 x 16^0) = 2748
2748 : 8 = 343 | R = 4
343 : 8 = 42 | R = 7
42 : 8 = 5 | R = 2
5 : 8 = 0 | R = 5
= 5274
d) 0XCBA
(12 x 16^2) + (11 x 16^1) +(10 x 16^0) = 3258
3258 : 8 = 407 R 2
407 : 8 = 50 R 7
50 : 8 = 6 R 2
6 : 8 = 0 R 6
= 6272
a) 010E2
It is a legal float
The result is 1000.000000.
b) 32.1E+5
It is a legal float.
The result is 321000.
c) 0790
It is an illegal constant.
If it is started by 0, it is an octal. However, the digits of
octal only ranges from 0 to 7, “9” will not be accepted.
d) 100_000
It is an illegal constant.
Cannot exist in any constant, not even in decimal.
Underscore is not allowed in a constant.
e) 3.978e-2
It is a legal float
The result will be 0.039780
a) ‘A’
b) 0b1000001
c) 0101
d) 0x41
i / j + ‘a’ ?
The answer is int because int a has wider range than chars
(‘a’). Int can accommodate the operands.
i * f / d ?
10. Assuming
char c = ‘1’;
short s = 2;
int i = -3;
long m = 5;
float f = 6.5f
double d = 7.5;
a) c * i
49 * -3 = -157
The type is int because int has a wider range than char.
Int is safer to accommodate both the operands.
b) s + m
2 + 5 = 7
The type is long because long has a wider range than short.
long is safer to accommodate both the operands.
c) f / c
6.5 / 49 = 0.132653
The type is float because float has a wider range than char.
Float is safer to accommodate both the operands.
d) d / s
7.5 / 2 = 3.75
The type is double because double has a wider range than short.
Double is safer to accommodate both the operands.
e) f – d
6.5f – 7.5 = -1
The type is double because double has a wider range than float.
Double is safer to accommodate both the operands.
f) (int) f
= 7
Because it will be truncated after f is casted to int (the
decimal will not be brought).