Practice question · Multiple choice
In mathematics x = x + 1 is a contradiction with no solution. In most programming languages it is a routine instruction. Why do the same symbols mean such different things?
Hints
- Ask what the machine actually does, step by step, when it executes the line.
- Which x is evaluated first, and which one is written to?
Show the answer
C. Because the programming version is an instruction, not an assertion.
Why
The line is a command with an order of operations: evaluate the right side using the current x, then store the result. Nothing is asserted, so nothing can be contradicted, and the two x's are different moments the notation conceals. A mathematical variable stands for one fixed value throughout; a program variable is a container whose contents change over time.
Practise Variables, Types, and Expressions
The app has 4 more questions on this lesson, and keeps your place in the course. Mathematics I is free to start.
More questions on Variables, Types, and Expressions
- In most languages 0.1 + 0.2 == 0.3 evaluates to false. Why do experienced programmers compare floats with a…
- Match each data type to its defining property.
- Order the evaluation steps of the expression 2 + 3 * (8 - 6) / 2.
- Select every statement that is TRUE.
- Because a float stores only finitely many digits, two computations that are mathematically equal can produce…
- The symbol + adds numbers but joins text. Sort each expression by what + actually does.