Skip to content
Sign in
Computer PPSC

x = 5 what is the value of x++?

Tap an option to check the answer. You can also press A–D.

Show answer

Correct answer: D) 5

x++ is the post-increment operator: the expression evaluates to the current value of x (5), and only afterwards is x increased to 6. So the value of the expression x++ itself is 5. Related facts: ++x (pre-increment) would evaluate to 6, since x is increased first.x-- is the post-decrement operator. These operators come from the C programming language and are used in C++, Java and JavaScript. Exam tip: Operator questions test the difference between pre- and post-increment; remember 'post = old value first'.
Explanation
x++ is the post-increment operator: the expression evaluates to the current value of x (5), and only afterwards is x increased to 6. So the value of the expression x++ itself is 5. Related facts: ++x (pre-increment) would evaluate to 6, since x is increased first.x-- is the post-decrement operator. These operators come from the C programming language and are used in C++, Java and JavaScript. Exam tip: Operator questions test the difference between pre- and post-increment; remember 'post = old value first'.