Let’s say I have 3 separate arrays (which could be combined into a two-dimensional array, but let’s say that’s not allowed) of equal size.
I want to use a for loop to step through these arrays. We all know the subscript of an array can be referenced dynamically:
for (int i = 0; i < size; i++)
{
cout << array1[i];
}
But how can I jump to the next array programmatically/dynamically? I.E. nested for loop.
How can I do something akin to arrayX[i]?
Other than condensing separate variables (or arrays) into arrays, to enable dynamic stepping via the subscript, is there any way to do this?
I’ve considered the idea of using pointers, but I believe that would have to rely on the assumption that these arrays would be allocated sequentially in memory, using the known memory size of the array as an offset and making calculated jumps. Is this typically the rule with C++ if variables/arrays are declared immediately after each other or in the same line? If not, is there a way to ensure this?
I tried writing the function calls out individually, which is not scalable.
1