Conversions Worksheet

Suppose we are given the following declarations:

   int i = 15;
   short s = 25;
   long m = 50;
   float f = 2.5;
   double d = 0.25;

For each of the following assignment statements, tell whether there will be an error or show the value that will be stored in the variable on the left hand side. If there is a promotion (conversion of a variable on the right hand side, point that out.

   1.  i = s + 1;

   2.  f = i * 2;

   3.  i = f * 2;

   4.  i = (int) f + 2;

   5.  i = (int) (d * 2);

   6.  d = f * i + 1;

   7.  f = d + 1;

   8.  s = 5;

   9.  f = 3.14;

   10. s = (short) 5;

   11. f = 3.14F;

   12. f = (float) 3.14;

   13. m = 12L;

   14. i = m + 1;

   15. i = (int) m + 1;

   16. m = i + 1;


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2013