AP Computer Science A Practice Quiz: Compound Assignment Operators
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 9 questions to check your progress.
Question 1 of 9
All Questions (9)
A) 5
B) 10
C) 15
D) 20
Correct Answer: C
The compound assignment operator `+=` adds the value on the right (5) to the current value of the variable on the left (`score`, which is 10). The result, 15, is then assigned back to `score`.
A) x += 4;
B) x *= 4;
C) x /= 4;
D) x %= 4;
Correct Answer: B
The compound assignment operator `*=` performs multiplication. The expression `x *= 4;` multiplies the current value of `x` by 4 and assigns the result back to `x`, which is the same operation as `x = x * 4;`.
A) 5
B) 5.66
C) 6
D) 2
Correct Answer: A
The compound assignment operator `/=` performs integer division because `value` is an integer. 17 divided by 3 is 5 with a remainder of 2. In integer division, the fractional part is truncated, so the result is 5. This value is then assigned to `value`.
A) 7
B) 8
C) 9
D) -1
Correct Answer: A
The post-decrement operator `--` subtracts 1 from the stored value of the variable. The initial value of `count` is 8, so after `count--`, its new value is 7.
A) 2
B) 3
C) 4
D) 20
Correct Answer: A
The compound assignment operator `%=` performs the modulo (remainder) operation. It divides the value on the left (20) by the value on the right (6) and assigns the remainder to the variable on the left. 20 divided by 6 is 3 with a remainder of 2. Therefore, the value 2 is assigned to `num`.
A) 9
B) 10
C) 11
D) 15
Correct Answer: C
The code executes in sequence: 1. `result` starts at 5. 2. `result *= 3;` changes `result` to 5 * 3 = 15. 3. `result -= 5;` changes `result` to 15 - 5 = 10. 4. `result++;` changes `result` to 10 + 1 = 11.
A) The post-increment operator `++`
B) The subtraction assignment operator `-=`
C) The modulo assignment operator `%=`
D) The multiplication assignment operator `*=`
Correct Answer: A
The post-increment operator `++` is specifically used to add 1 to the stored value of a numeric variable. `items++` is equivalent to `items = items + 1` or `items += 1`.
A) 0
B) 10
C) 20
D) 30
Correct Answer: A
The code executes in sequence: 1. `x` starts at 25. 2. `x /= 2;` performs integer division, changing `x` to 12 (25 / 2 = 12.5, truncated to 12). 3. `x %= 3;` calculates the remainder of 12 / 3, which is 0. `x` becomes 0. 4. `x *= 10;` changes `x` to 0 * 10 = 0.
A) 10
B) 15
C) 50
D) 90
Correct Answer: A
The code executes in sequence: 1. `quantity` starts at 100. 2. `quantity -= 50;` changes `quantity` to 100 - 50 = 50. 3. `quantity /= 5;` changes `quantity` to 50 / 5 = 10.