It doesn’t matter which one you use, the program output will be identical; i++
and ++i
are not the termination conditions in the for
loop but are statements evaluated at the end of each iteration.
Note however that ++i
will never be slower than i++
; as conceptually an object copy has to be taken for the latter. A good compiler will optimise out the copy though.
And a point of style: please indent the line sum = sum + i;
; it’s hard to read otherwise.
solved the number of execution time of 2 code will differ? [closed]