#include <iostream>
usingnamespace std;
# define width 5
# define height 6
int yo [width] [height];
int x,y;
int main()
{
for (x=0; x<width; x++)
for (y=0;y<height; y++)
{
yo[x][y]= x;
cout << yo[x][y]<< endl;
}
return 0;
}
Hi, I was taking one of the examples and altering it. After the for loop, I assign the value of x to yo[x][y]. 0 to 4 repeats itself six times because [y] (that is, height) has the value of 6. In this case the numbers should also repeat five times again because [x] (that is, width) has a value of 5. But it does not do so. Why? Please correct me if my analysis is wrong.
You are then printing this array in column major order... that is:
column 0, row 0
column 0, row 1
column 0, row 2
...
column 0, row 5
column 1, row 0
column 1, row 1
...
etc
The values repeat 6 times because you are printing the first column of data... all of which is the same value.
It does not repeat an additional 5 times because each column has different data.