1. Assume the following rules of associativity and precedence for expressions
Precedence:
Highest
*, /, not
+, -
- (unary minus)
=, /=, <, <=, >= , >
and
or, xor
Lowest
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. For example, for the expression
a + b * c + d
the order of evaluation would be represented as
((a + ( b * c )1)2 + d)3
2.
Let the function FUN be defined as
int FUN ( int & T )
{
T =T + 2;
return T;
}
Suppose FUN is used in a program as follows
I = 200;
sum1 = FUN( I ) + I * 2;
J = 10;
sum2 = ( J / 2 ) + FUN( J );
What are the values of sum1 and sum2
3. Rewrite the following code segment using a loop structure in C/C++
A = T + 2;
Loop:
B = A * 3;
B++;
If (B < 100) goto Loop;
T = T + A;
4. Suppose that C++ did not have short circuiting in Boolean expressions. Rewrite the following code to avoid ever dividing by zero:
cin >> Z >> X;
if ( Z != 0 && X / Z < 3 )
cout << Z;
cout << X;