041-array-2d.c (492B)
1 // tests/cc-parse/41-array-2d.c — multi-dim array indexing. int a[2][3]; 2 // row-major, so &a[1][2] is at byte offset (1*3 + 2)*4 = 20 from a's 3 // base. We write distinct values into a[0][0]..a[1][2] and read them 4 // back via a known sum. 5 // 6 // Sum is 0 + 1 + 2 + 10 + 11 + 12 = 36. 7 8 int main() { 9 int a[2][3]; 10 a[0][0] = 0; 11 a[0][1] = 1; 12 a[0][2] = 2; 13 a[1][0] = 10; 14 a[1][1] = 11; 15 a[1][2] = 12; 16 return a[0][0] + a[0][1] + a[0][2] + a[1][0] + a[1][1] + a[1][2]; 17 }