I want to access the first array element after a loop completes executing.
I have an array that stores some numbers like 1,2,3,4,5. The array is always initialized with index 0 but I’m not using 0th index to store anything.
So what I want is using indexes in ring fashion like 1-2-3-4-5-1 I can achieve this if I use array from 0th index like 0-1-2-3-4-0 with modulus operation.
How can do that when my array index starts from 1 instead?
You can subtract one, do
%, and add one back:This illustrates a problem of fighting the convention: instead of a simple
%operation, you need a subtraction, a%, and an addition. Tather than fighting the C/C++ convention, it’s best to embrace it for more efficiency and readability by others.