HW3: Due 5/21/98. ================== 1) What significant justification is there for the -> operator in C and C++ ? 2) Assume the following rules of associativity and precedence for expressions: Precedence: Highest *,/,not +,-,&,mod -(unary) =,<>,<,<=,>=,> and Lowest or,xor Associativity: Left to right Show the order of evaluation of the following expressions by parenthesizing all subexpressions and placing a superscript on the right parenthesis to indicate order. a) a * b - 1 + c b) a * (b - 1) / c mod d c) (a - b) / c & (d * e / a -3) d) -a or c = d and e e) a > b xor c or d <= 17 f) - a + b 3) Consider the following C program: int fun (int *i) { *i += 5; return *i; } void main () { int x = 3; x = x + fun (&x); } What is the value of x after the assignment stmt in main, assuming, a) operands are evaluated left to right b) operands are evaluated right to left. 4) Compare the FORTRAN computed GOTO with the Pascal case stmt, especially in terms of readability and reliability. 5) Rewrite the following code segment using loop structure in the following languages: a) Pascal b) FORTRAN 77 c) Ada d) C k := (j + 13) / 27 loop: if k > 10 then goto out k := k + 1 i := 3 * k - 1 goto loop out: .... Assume all variables are integer type. Discuss which language, for this code has best writability, best readability, and the best combination of two. 6) Consider the following ALGOL 60 style for statement: for i := j + 1 step i * j until 3 * j do j := j + 1 Assume that the initial value of j is 1. List the sequence of values for the variable i used, assuming the following semantics: a) All expressions are evaluated once at loop entry. b) All expressions are evaluated before at each iteration. c) step expressions are evaluated once at loop entry, and until expressions are evaluated before each iteration. d) until expressions are evaluated once at loop entry, and step expressions are evaluated before each iteration, just before the loop counter is incremented. In all cases, when more than one expression is evaluated at the same time, they are evaluated in left-to-right order. Also, the assignment is always done as soon as its RHS is evaluated.