What does the operator -= do?

Prepare for the Computer Programming Test. Dive into a world of coding with multiple choice questions, flashcards, and detailed explanations. Boost your knowledge and be exam-ready!

Multiple Choice

What does the operator -= do?

Explanation:
The subtract-assign operator first subtracts the right-hand side value from the variable on the left, then stores that result back into the left-hand variable. In other words, it’s the same as writing x = x - value. For example, if a variable starts at 10 and you do var -= 3, it becomes 7. This makes it convenient to decrease a variable by a certain amount in one step. It’s different from general subtraction, which computes a difference without saving it back; the compound form specifically updates the variable with the new value.

The subtract-assign operator first subtracts the right-hand side value from the variable on the left, then stores that result back into the left-hand variable. In other words, it’s the same as writing x = x - value. For example, if a variable starts at 10 and you do var -= 3, it becomes 7. This makes it convenient to decrease a variable by a certain amount in one step. It’s different from general subtraction, which computes a difference without saving it back; the compound form specifically updates the variable with the new value.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy