C/C++ Arena

Step 5 of 6

Prefix vs postfix ++

x++ and ++x both add 1 to x, but they differ when used inside a bigger expression:

int a = 5;
int b = a++;   // b = 5, a = 6
int c = ++a;   // a = 7, c = 7

Your turn: make the program print 5 7 7 by choosing prefix or postfix for each blank. The variable a starts at 5.

Previous: Shorthand operators Next: Put it together