If as an example a = 2, then arr[a++] requires the storage of the old value of a since after evaluating a++, a would be equal to 3, while it needs to access arr[2].
#ActuallyAutistic web dev. Does front of the front-end. Loves perf and minimalism. Prefers HTML, CSS, Web Standards over JS, UX over DX. Hates div disease.
I didn't get why compiler is storing value temporarily? Am I missing something?
If as an example
a = 2
, thenarr[a++]
requires the storage of the old value ofa
since after evaluatinga++
,a
would be equal to3
, while it needs to accessarr[2]
.I have not studied compilers, but this is what I think is the difference:
arr[i++]
i
++
which will incrementi
i
to accessarr
, so it makes a temporary clone before incrementi
arr
with value of temporary cloneValue of
i
cannot be used directly because it has been mutated, so a clone with previous value is required.arr[++i]
++
which will incrementi
i
arr
with value ofi
Value of
i
can be used directly.