0
0
C++programming~5 mins

Increment and decrement operators in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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;
Ax = 5, y = 6
Bx = 6, y = 6
Cx = 6, y = 5
Dx = 5, y = 5
What is the value of y after this code? int x = 5; int y = x++;
Ay = 6
By = 4
Cy = 7
Dy = 5
Which operator decreases a variable's value by 1?
A--
B++
C+=
D-=
If int x = 10; what is the value of x after x--?
A9
B10
C11
DUndefined
Can you use ++ operator on a pointer variable?
ANo, ++ only works on integers.
BYes, but it resets the pointer to null.
CYes, it moves the pointer to the next memory location.
DNo, pointers cannot be changed.
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.