int a[10][5];
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
cout << i[j[a]];
cout << j[i[a]];
}
}
Edit:assume the values are already initialized to the array and is this cout valid then?
please explain the i[j[a]]; part only regardless of the program I’m concerned about that statement only!
C arrays have a strange quirk that allows them to be accessed through the “opposite” direction. This is deeply rooted in the pointer arithmetic of arrays. For example,
a[1]is equivalent to*(a + 1). Likewise,1[a]is equivalent to*(1 + a). Due to the commutative nature of addition, this works out quite nicely. More details can be found here.With that knowledge in tact, the expression
i[j[a]]can be broken down into two different parts.j[a]is equivalent to*(j + a)which would return another array due to the multi-dimensional nature of the array you have, for example purposes we’ll call this returned arrayp. Then you have the statementi[p]which would be equivalent to*(i + p). Bringing it back all together would show you thati[j[a]]is equivalent to*(i + *(j + a)). Indeed, this means thati[j[a]]is just an obfuscated way of writinga[j][i].