Variable CS Thinking Example 1

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

Example 1

easy
Trace: SET x = 7. SET y = x + 3. SET x = y * 2. OUTPUT x, y.

Solution

  1. 1
    Step 1: x = 7.
  2. 2
    Step 2: y = 7 + 3 = 10.
  3. 3
    Step 3: x = 10 * 2 = 20. Output: x = 20, y = 10.

Answer

x = 20, y = 10.
Variables are named containers for storing values. When we reassign a variable, the old value is replaced. Other variables that used the old value are not affected.

About Variable

A named container in a program that stores a value, which can be read, updated, or replaced. Variables have a name (identifier), a value (the data stored), and in many languages a type (what kind of data it holds).

Learn more about Variable โ†’

More Variable Examples