Compound Assignment Operators - AP Computer Science A
- What is the result after 'z *= 3' if z is 7?
- 21. 7 × 3 = 21, then assigned back to z.
- What does 'x -= y' do to x?
- Decreases x by y. Equivalent to x = x - y.
- What does 'x += y' do to x?
- Increases x by y. Equivalent to x = x + y.
- Which operator performs division and assignment?
- /=. Combines division (/) with assignment (=).
- What operation does 'x %= 5' perform?
- Assigns remainder of x divided by 5. Uses modulo operator to find remainder.
- Which operator is used for addition and assignment?
- +=. Combines addition (+) with assignment (=).
- Identify the compound assignment operator in 'x += 5'.
- +=. The += operator is clearly visible in the expression.
- What does the operator '*=' in 'x *= y' do?
- Multiplies x by y and assigns. Equivalent to x = x * y.
- What does '/=' do in terms of operation?
- Divides left operand by right and assigns. Equivalent to x = x / (right operand).
- State the operation for '-=' in code.
- Subtracts right operand from left and assigns. Equivalent to x = x - (right operand).
- What result does 'x %= 4' give if x is 9?
- 1. 9 mod 4 = 1, then assigned back to x.
- What is the result of 'x *= 3' if x is initially 2?
- 6. 2 × 3 = 6, then assigned back to x.
- Which compound assignment operator multiplies and assigns?
- =. Combines multiplication () with assignment (=).
- Find the result: 'x %= 3' when x is 10.
- 1. 10 mod 3 = 1, then assigned back to x.
- What is the result of 'y /= 2' if y is 9?
- 4.5. 9 ÷ 2 = 4.5, then assigned back to y.
- What does the operator '+=' do?
- Adds right operand to left and assigns the result. Equivalent to x = x + (right operand).