Output Prediction
Problem
What will be the output of the following C code?
#include <stdio.h>
int main() {
int x = 5;
printf("%d", x++ + ++x);
return 0;
}
Solution
x++ is post-increment: uses value 5, then increments to 6
++x is pre-increment: increments 6 to 7, then uses value 7
Result: 5 + 7 = 12