Free Response Question 2: Expression Evaluation

In this lesson, you will use your knowledge about data types, operators, and type casting to solve a coding challenge.

We'll cover the following

Unlike the previous free-response question (FRQ), this FRQ tests your ability to read code and keep track of variables’ values.

The task at hand

On the surface, the challenge seems to be simple. The code below presents a few arithmetic operations on three variables x, y, and z. You need to keep track of the changes in all of these variables. In the end, you are required to determine what value is stored in the variable x.

Somethings you will need to pay special attention to:

  • Notice the types of all the variables; some operators work differently for different types.
  • Recall the precedence of various operations. Recall what happens when we have operators with the same precedence in an equation.

Keep track of changes in each of the three variables at each line of code. Having a piece of paper and a pencil with you might help with this exercise.

How to check your answer?

You only need to submit the value of the variable x. This value will be of int type.

If your answer is correct, you will get an output similar to this:

Your answer: XX


XX is correct! Great job!

If your answer is incorrect, you will get the following output:

Your answer: XX


XX is incorrect. Give it another try!

For the answer, see the next lesson.

How to submit the answer?

To submit your answer, first press the STDIN button at the bottom of the code widget below. You will get a blank field. Enter your answer there, and then press Run.

Try to dry run the code below to find x. Don’t forget to use the concepts taught in the previous lessons after giving it a few shots. Feel free to view the solution in the next lesson. Good luck!