Is it good practice to increment or decrement array index while accessing it?

Viewed 22

int[] a = new int[10]; int index;

//Assume index is checked so that it won't go out of bound.

Option 1: int sample = a[index++];

Option 2: int sample = a[index]; index++;

or

Option 1: int sample = a[--index];

Option2: index--; int sample = a[index];

Do we generally prefer option1 or option2? Does option 2 provide better code readability?

0 Answers
Related