Computer Science, asked by MolikJoshi, 6 months ago

state with reasons why are the following intializations incorrect
a.int a=5
short b=a;

b.double a=5.3;
float b=a;

c.int a=01238;

d.float a=17.36f;
int b=a;

e.boolean a=true;
int b=a;​

Answers

Answered by pratikchoudhari
16

Answer:

All initializations are invalid

Explanation:

a. The range of number that int datatype holds is far more than what short can hold. If a is in -32767 and 32767 then there will be no problem but as soon as a exceeds this range b will contain garbage values.

b. Here too the reason is same as point a. Double can hold a wider range of floating point numbers that float can hold.

c. Initializing int with 0 at start signals assignment of octal values(0-7). Number 8 is not permitted in octal system therefore error will be thrown.

d. floating point numbers can not be initialized as integers, only way to do so is by rounding off them to nearest integers.

e. boolean and int are two different data types and therefore such initialization is illegal .

Similar questions