Yes. But behind the scenes, it's a little more complicated than that.
Code:
int a = 0;
int b = a++;
//b equals 0 here, while a = 1
Here's what actually happened.
a was created and initialized to zero
a was copied
a was incremented
b was created, then initialized to the copy
Code:
int a = 0;
int b = ++a;
//a and b both equal 1
a was created and initialized to 0
a was incremented
b was created and initialized to zero
The difference is that copy. Copying takes time and in the case a few posts ago, a copy is not needed and just wastes ram and cpu power. Optimizing software is all about removing extra steps.
Bookmarks