BrainTok
ENESIT

Programming Fundamentals: Variables, types and expressions · Variables and Assignment

How variables name stored values, how assignment changes them step by step, and why two names can share one object.

Programming Fundamentals · 28 questions

Try 3 questions

1. After running x = 5, then y = x, then x = 8, what value does y hold?

  1. 13
  2. 8
  3. 5
Show the answer

Answer: 5

y = x copies the value x had at that moment; changing x later does not reach back and change y.

2. In most programming languages, what does the statement x = x + 1 do?

  1. Stores x's value plus one back in x
  2. States an equation with no solution
  3. Checks whether x equals x plus one
Show the answer

Answer: Stores x's value plus one back in x

In code, = is an instruction: evaluate the right side, then store the result in the variable on the left.

3. Someone tries to swap a and b by writing a = b, then b = a. What actually happens?

  1. Both end up with a's original value
  2. Both end up with b's original value
  3. The two values are swapped correctly
Show the answer

Answer: Both end up with b's original value

The first line overwrites a with b's value, so a's original value is lost before the second line can use it.

The rest of the quiz, a few questions at a time

BrainTok asks a few questions from quizzes like these before the apps you choose open, so your screen time turns into learning. For iPhone.

Join the beta

More Computer Science quizzes