Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Afaik it doesn't matter, the only difference is the return value (i.e. the i before or after the addition)
-
303Tek3718yIt depends:
It's your i angry? Put it in the front of ++ so you can see when she misbehaves.
If you have a cool, relaxed i instead, the order doesn't matter. -
loop truu an array and start witth 0++
i is/are berter than array[i+1] as lonng as you donn¨t code druk -
BartBB6898yYes, the answer is yes. ++i is more efficient because when you use the ++ operator in such a way, before the variable, it will up the variable by one and immediately return it.
x = x + 1;
return x;
However, i++ makes a temporary variable, meaning it takes more memory, it assigns the current value of i to the temporary variable and adds one to i and it returns the temporary variable, which is the value before increment.
int temp = x;
x = x + 1;
return temp;
So, it is a bit less efficient, but you won't die from using i++ over ++i.
Related Rants
Is "++i" more efficient or "i++" ?
P.S. I already wasted more cpu cycles by posting this, than I would ever waste by using either of them....
undefined
waste
cpu
efficient code
++
iteration