PrepGo

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

Consider the following code segment: int score = 10; score += 5; What is the value of `score` after this code segment is executed?

All Questions (9)

Consider the following code segment: int score = 10; score += 5; What is the value of `score` after this code segment is executed?

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`.

Which of the following code statements is equivalent to `x = x * 4;`?

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;`.

Consider the following code segment: int value = 17; value /= 3; What is the value of `value` after this code segment is executed?

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`.

Consider the following code segment: int count = 8; count--; What is the value of `count` after this code segment is executed?

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.

Consider the following code segment: int num = 20; num %= 6; What is the value of `num` after this code segment is executed?

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`.

Consider the following code segment: int result = 5; result *= 3; result -= 5; result++; What is the final value of `result`?

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 programmer wants to add 1 to a numeric variable named `items`. Which of the following operators can be used to accomplish this?

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`.

Consider the following code segment: int x = 25; x /= 2; x %= 3; x *= 10; What is the final value of `x`?

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.

Consider the following code segment: int quantity = 100; quantity -= 50; quantity /= 5; What is the final value of `quantity`?

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.