Lecture 1 - Intro Flashcards

1
Q

What is the difference between i++ and ++i?

A

i++ and ++i are very similar but not exactly the same. Both increment the number, but ++i increments the number before the current expression is evaluted, whereas i++ increments the number after the expression is evaluated.

int a = 0;
int b = a++; // b = 0; a = 1

a = 0;
b = ++a: // b = 1; a = 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly