Increment and Assignment Worksheet


For each of the following groups of statements, show the value of each variable that will be changed by each assignment statement. Assume that the statements are executed in sequence, so that each uses the values from the previous statements. Assume that you are given the following declarations:

   int num;
   int amount;
   float val;


  1. num = 10;
     num = num + 1;
     num = num + 1;
     num = num * 2;

  2. num = 10;
     val = 2.5;
     num++;
     val += num;

  3. num = 10;
     amount = 2 * num++;

  4. num = 10;
     amount = 2 * ++num;

  5. num = 3;
     val = 2.5;
     val *= 4 + num * 2;

  6. num = 4;
     amount = 2;
     val = 2.0;
     num--;
     num -= amount++ * 5 / (val + 2) - 1;

  7. num = 5;
     (num++)++;
     num *= 4;


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

© Copyright Emmi Schatz 2002