4. Expressions¶


Q) Expression Trees:¶

Drawing the following expression as an expression tree (assume x is an integer and equals 0)

int x;
  x = 5 * 4 + 2 - 1;

If you read the operators in the tree, from top to bottom, what would they be?

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


Q) Make equal 4:¶

Given the following variable declaration:

int x = 2;

Which of the following expressions makes x equal to 4?

a) x += 2 + 2;
b) x = x + 4;
c) x *= 2;
d) x /= 4;


Answers¶

a) = - + *
c) x *= 2;