PrepGo

AP Computer Science A Flashcards: Compound Assignment Operators

Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026

Review key ideas with interactive flashcards. This set includes 10 cards to help you master important concepts.

What is the primary goal when developing code with compound assignment operators?
The primary goal is to correctly use the operators in assignment statements and determine the final value that is stored in the variable as a result.
Card 1 of 10

All Flashcards (10)

What is the primary goal when developing code with compound assignment operators?
The primary goal is to correctly use the operators in assignment statements and determine the final value that is stored in the variable as a result.
What is the purpose of the post-decrement operator (--)?
The post-decrement operator is used to subtract 1 from the stored value of a numeric variable, and the new value is assigned to that variable.
If `int x = 10;`, what is the value of `x` after the statement `x += 5;` is executed?
The value of x becomes 15. The operator adds 5 to 10 and assigns the result back to x.
If `int z = 17;`, what is the value of `z` after the statement `z %= 5;` is executed?
The value of z becomes 2. The operator finds the remainder of 17 divided by 5 and assigns the result back to z.
What is the purpose of the post-increment operator (++)?
The post-increment operator is used to add 1 to the stored value of a numeric variable, and the new value is assigned to that variable.
How does a compound assignment operator function?
It performs an arithmetic operation between the value on the left and the value on the right, then assigns the result to the variable on the left.
If `int val = 8;`, what is the value of `val` after the statement `val -= 3;` is executed?
The value of val becomes 5. The operator subtracts 3 from 8 and assigns the result back to val.
If `int count = 99;`, what is the value of `count` after `count++;` is executed?
The value of count becomes 100. The post-increment operator adds 1 to the variable's stored value.
What are the five compound assignment operators for numeric expressions mentioned in the text?
The five compound assignment operators are +=, -=, *=, /=, and %=.
If `int y = 20;`, what is the value of `y` after the statement `y /= 4;` is executed?
The value of y becomes 5. The operator divides 20 by 4 and assigns the result back to y.