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?
- 13
- 8
- 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?
- Stores x's value plus one back in x
- States an equation with no solution
- 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?
- Both end up with a's original value
- Both end up with b's original value
- 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 betaMore Computer Science quizzes
- Artificial Intelligence: Intelligent agents and environments · Agents, Percepts and Rationality
- Artificial Intelligence: Why Chess Was Easier Than Laundry
- Computer Architecture: Data representation and binary arithmetic · Binary and Hexadecimal Numbers
- Computer Architecture: Why Your Processor Guesses the Future
- Computer Networks: Layered models: OSI and TCP/IP · The Seven Layers of the OSI Model
- Computer Networks: Why the Internet Never Promises Delivery