Assignment CS Thinking Example 3

Follow the full solution, then compare it with the other examples linked below.

Example 3

easy
What is the output? SET a = 3. SET b = 4. SET a = a + b. SET b = a - b. OUTPUT a, b.

Solution

  1. 1
    Step 1: a = 3, b = 4. Then a = 3 + 4 = 7.
  2. 2
    Step 2: b = 7 - 4 = 3. Output: a = 7, b = 3.

Answer

a = 7, b = 3.
Each assignment uses the current values of variables at that moment. After the operations, a holds the sum and b holds the original value of a.

About Assignment

The operation of storing a value in a variable. The variable name goes on the left of the assignment operator, and the value or expression goes on the right. The right side is evaluated first, then the result is stored in the variable on the left.

Learn more about Assignment โ†’

More Assignment Examples