Compound Assignment Operators - AP Computer Science A

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

Study these flashcards