0
0
Cprogramming~5 mins

Assignment operators in C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ADivides x by 4 and stores the result in x
BAssigns 4 to x
CMultiplies x by 4 and stores the result in x
DAdds 4 to x and stores the result in x
Which operator assigns the value on the right to the variable on the left?
A!=
B==
C+=
D=
What is the result of int a = 2; a += 3;?
Aa is 5
Ba is 6
Ca is 3
Da is 2
What does the statement c = a = 10; do?
AAssigns 10 to a only
BAssigns 10 to both a and c
CAssigns 10 to c only
DCauses a syntax error
Which operator subtracts and assigns in one step?
A-=
B+=
C*=
D/=
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.