Computer Science I / Variables, Expressions, and Types
Practice question · Put in order

Order what the machine does when it runs the single line x = x + 1, given that x currently holds 7.

Hints
  1. The right-hand side is fully evaluated before any storing happens.
  2. The old value is read before the new value is written, so there is no contradiction.
Show the answer
  1. Read the current value of x, which is 7
  2. Add 1 to that value, giving 8
  3. Store 8 back into x, overwriting the old value
  4. From now on the name x refers to 8
Why

Read, compute, store, then the name carries the new value. Because the read happens before the write, x = x + 1 is a command and not a false equation, the very point this lesson insists on.

Read the lesson: Variables, Expressions, and Types →

Practise Variables, Expressions, and Types

The app has 6 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.

More questions on Variables, Expressions, and Types