Recall & Review
beginner
What does the increment operator (++) do in C++?
The increment operator (++) increases the value of a variable by 1.
Click to reveal answer
intermediate
Explain the difference between prefix (++x) and postfix (x++) increment operators.
Prefix (++x) increases the value first, then uses it. Postfix (x++) uses the current value first, then increases it.
Click to reveal answer
beginner
What does the decrement operator (--) do in C++?
The decrement operator (--) decreases the value of a variable by 1.
Click to reveal answer
intermediate
How does the postfix decrement operator (x--) behave in an expression?
It uses the current value of x in the expression, then decreases x by 1 after.
Click to reveal answer
advanced
Can increment and decrement operators be used with non-integer types like floats or pointers?
Yes. Increment and decrement operators can be used with floats (increase/decrease by 1.0) and pointers (move to next/previous memory address).
Click to reveal answer
What is the value of x after this code? int x = 5; int y = ++x;
✗ Incorrect
Prefix ++x increases x first to 6, then assigns y = 6.
What is the value of y after this code? int x = 5; int y = x++;
✗ Incorrect
Postfix x++ uses x's current value (5) for y, then increments x.
Which operator decreases a variable's value by 1?
✗ Incorrect
The decrement operator (--) decreases the value by 1.
If int x = 10; what is the value of x after x--?
✗ Incorrect
x-- decreases x by 1, so x becomes 9.
Can you use ++ operator on a pointer variable?
✗ Incorrect
Incrementing a pointer moves it to the next element in memory.
Describe how prefix and postfix increment operators differ in behavior.
Think about when the variable changes relative to its use.
You got /4 concepts.
Explain how decrement operators work and give an example with both prefix and postfix forms.
Compare with increment operators but in reverse.
You got /4 concepts.