Increment operators in programming

773 views

I’ve never been able to understand the difference between operators like x++ vs ++x. Please help explain these in a way my small brain can understand?

In: Technology

2 Answers

Anonymous 0 Comments

x = 5
print(x) // 5
print(x++) // 5
print(x) // 6
print(++x) // 7
print(x) // 7

Both `x++` and `++x` increment x by 1, but `x++` evaluates to the old value of x, while `++x` evaluates to the new value of x.

You are viewing 1 out of 2 answers, click here to view all answers.