Sequence CS Thinking Example 3
Follow the full solution, then compare it with the other examples linked below.
Example 3
easyWhat is the output? SET a = 10. SET b = a * 2. SET a = 0. OUTPUT b.
Solution
- 1 Step 1: a = 10. b = 10 * 2 = 20. Then a is changed to 0, but b already holds 20.
- 2 Step 2: Output: 20.
Answer
Once b is assigned the value 20, changing a does not affect b. Variables store values at the time of assignment, not references to expressions.
About Sequence
Executing a series of instructions one after another in a fixed, specific order. In sequential execution, each instruction must complete before the next one begins, and the order in which statements appear determines the order in which they run.
Learn more about Sequence โMore Sequence Examples
Example 1 easy
What is the output of this sequence of instructions? SET x = 5. SET y = 3. SET z = x + y. OUTPUT z.
Example 2 easyRearrange these steps into the correct sequence for logging into a website: (A) Click 'Login'. (B) E
Example 4 easyTrace this pseudocode: SET x = 2. SET y = x + 4. SET x = y * 2. OUTPUT x, y.