0
0
Cprogramming~5 mins

Increment and decrement operators - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the increment operator (++) do in C?
It increases the value of a variable by 1.
Click to reveal answer
intermediate
What is the difference between prefix (++x) and postfix (x++) increment?
Prefix increments the value before using it, postfix uses the value first then increments it.
Click to reveal answer
beginner
What does the decrement operator (--) do in C?
It decreases the value of a variable by 1.
Click to reveal answer
intermediate
How does the postfix decrement (x--) behave in an expression?
It uses the current value of x in the expression, then decreases x by 1.
Click to reveal answer
advanced
Can increment and decrement operators be used with non-integer types in C?
Yes, they can be used with types like char and pointers, increasing or decreasing their value accordingly.
Click to reveal answer
What will be the value of x after this code? <br> int x = 5; <br> x++;
A6
B5
C4
DError
What is the output of this code? <br> int x = 3; <br> printf("%d", ++x);
AError
B3
CUndefined
D4
Which operator decreases a variable's value by 1?
A++
B--
C+=
D-=
What is the difference between x++ and ++x in expressions?
Ax++ increments after use, ++x increments before use
Bx++ increments before use, ++x increments after use
CNo difference
DBoth cause errors
Can you use increment operators on pointers in C?
AYes, but only on char pointers
BNo, only on integers
CYes, it moves the pointer to the next memory location
DOnly on arrays
Explain how prefix and postfix increment operators work differently in C.
Think about when the variable's value changes relative to its use.
You got /3 concepts.
    Describe how decrement operators can be used with pointers and what effect they have.
    Consider how memory addresses change when you decrement a pointer.
    You got /3 concepts.