can you do array[i]++
?
Is it the same as array[i] = array[i] + 1
?
If not, why not? Is it something to do with how primitives vs references are treated?
can you do array[i]++
?
Is it the same as array[i] = array[i] + 1
?
If not, why not? Is it something to do with how primitives vs references are treated?
There's a slight difference: postfix vs prefix increment operator
If you use array[i]++
, the old value will be used for the calculation and the value of i
will be increased by 1 afterwards.
For array[i] = array[i] + 1
, it's the opposite: i
will first be incremented and only then the calculation will take place.
For more details, check this out.