Recall & Review
beginner
What is the purpose of the assignment operator (=) in C?
The assignment operator (=) is used to store a value into a variable. It copies the value on the right side into the variable on the left side.
Click to reveal answer
beginner
Explain the shorthand assignment operator += with an example.
The operator += adds the right value to the left variable and then assigns the result back to the left variable. For example,
x += 3; means x = x + 3;.Click to reveal answer
beginner
List three common shorthand assignment operators in C.
Three common shorthand assignment operators are:<br>1. += (add and assign)<br>2. -= (subtract and assign)<br>3. *= (multiply and assign)
Click to reveal answer
intermediate
What happens if you write
a = b = 5; in C?This assigns the value 5 to variable b first, then assigns the value of b (which is 5) to variable a. Both a and b will have the value 5.
Click to reveal answer
intermediate
Can assignment operators be used with non-numeric types in C?
Yes, assignment operators can be used with any assignable type, such as characters, pointers, and structs (with some restrictions). The = operator copies the value from right to left.
Click to reveal answer
What does the expression
x *= 4; do in C?✗ Incorrect
The operator *= multiplies the variable by the right value and assigns the result back to the variable.
Which operator assigns the value on the right to the variable on the left?
✗ Incorrect
The single equals sign (=) is the assignment operator in C.
What is the result of
int a = 2; a += 3;?✗ Incorrect
The += operator adds 3 to a (which is 2), so a becomes 5.
What does the statement
c = a = 10; do?✗ Incorrect
Assignment operators can be chained. 10 is assigned to a, then a's value is assigned to c.
Which operator subtracts and assigns in one step?
✗ Incorrect
The -= operator subtracts the right value from the left variable and assigns the result back.
Explain how shorthand assignment operators work and give two examples.
Think about how operators combine math and assignment in one step.
You got /2 concepts.
Describe what happens when assignment operators are chained in a statement.
Remember that assignment returns a value that can be assigned again.
You got /3 concepts.