
Help for this exam paper Q
Help for this exam paper Q

Re: Help for this exam paper Q
value is defined a short type variable. But 2 is "int" by default. The error (warning) is loss of precision. Because "int" is 32bit of size. The result of (value*2) is going to be int as I think. Then has to be converted to short in order to be assigned to the "value". So the value has to be cast manually.
possible fixes for this are
But you can always cast a 16bit data type in to a 32bit or higher size type without any problem.
possible fixes for this are
Code: Select all
value=(short) ((short) value * (short) 2);
Code: Select all
value*=2;
Re: Help for this exam paper Q
thanks brother.!