Homework Assignment #3

  1. Describe the three major parts of a central processing unit and explain how they work together to execute a program. (Write your own answer. Do not copy from course notes and web materials.)

  2. The following program segment contains a collection of variable declarations. Point out and correct all invalid declarations.

    1

    2

    3

    4

    5

    6

    char character, CHAR;

    short a1, a, b;

    int 1a, ab, a&b;

    long aaaaaaaaaaaa1, bbbbbb0ccccccc, unsigned;

    long unsigned l0, O1, abc;

    float float, real, real-number;

  3. Consider the following C program.

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    #include <stdio.h>

    int main(void) {
    @

      int i=6, j=35, k=10;
      float r=2.98, s=1.1, t=3.21;

      k = s * s + j / i * r - k % i * 3;

      t = (r + s) * s - (t * j / 10);


      return 0;
    }

    Suppose the operands of a binary operation are evaluated from left to right. For each assignment of Lines 8 and 9, indicate the evaluation order of operations (including loading of operand values and execution of operators) in the right-hand-side expression. (Copy the expression to your solution and mark numbers 1, 2, 3, ¼, etc., under each operator and operand.) Also, for each operation indicate whether it is an integer operation or a floating-point operation. What are the final values of variables k and t?

  4. Suppose the operands of a binary operation are evaluated from left to right. Rewrite the following assignments to remove side effect in the expressions.

    (a)

    a = (++b * --c) + (c++ - d++);

    (b)

    r = (s = ++t / s--) * t;

    (c)

    w = (u = t - r * u) + (t = w / u + u) - (w = t * u);