Handmade Hero»Forums»Code
1 posts
C arrays: "what looks right to us"
Edited by soul-burn on
What did Casey mean here? I think this has been explained before, but can't remember in which episode(s)... :/
Ginger Bill
222 posts / 2 projects
I am ginger thus have no soul.
C arrays: "what looks right to us"
C has its arrays as row-major. This means that int array[17][9]; means that there are 17 rows and 9 columns. And when you the elements array[3][4] this is means that you have selected the 3rd row and 4 column, backwards to how many people think about coordinate systems.

For a 2d dimensional array, you usually imagine each cell with a coordiate (x,y). x refers to the column and y refers to the row. As you can see, this is the other way around to what C offers.

Another way to think to of it what array[3][4] actually is doing. The a[i] operator in C does the same thing as *(a + i).