Increment and Decrement Operators
C++
Easy
2 views
Problem Description
Understand difference between ++x (pre) and x++ (post).
Real Life: Like counting up or down in different ways.
Step-by-Step Logic:
1. Pre-increment (++x): increases value first, then uses it
2. Post-increment (x++): uses value first, then increases it
3. Same for decrement
4. See the difference in output
Official Solution
void operator_q2_increment_decrement() {
int x = 5;
cout << "Original value: " << x << endl;
cout << "Post increment (x++): " << x++ << endl;
cout << "Value after post increment: " << x << endl;
cout << "Pre increment (++x): " << ++x << endl;
cout << "Final value: " << x << endl;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!