Variable 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 score = 0. SET score = score + 10. SET score = score + 5. OUTPUT score.

Solution

  1. 1
    Step 1: score starts at 0, then 0 + 10 = 10, then 10 + 5 = 15.
  2. 2
    Step 2: Output: 15.

Answer

1515
The pattern `score = score + value` is called accumulation โ€” it adds to the existing value rather than replacing it.

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