Tsallaka zuwa abun ciki
Justice Tech School

Two Dimensional Arrays

Arrays of arrays model grids. Row major order.

Example
#include <stdio.h>

int main(void) {
  int g[2][3] = {{1, 2, 3}, {4, 5, 6}};
  for (int r = 0; r < 2; r++) {
    for (int c = 0; c < 3; c++) printf("%d ", g[r][c]);
    printf("\n");
  }
  return 0;
}

Result

1 2 3 
4 5 6 

Exercise

Second row first column.

g[][0]

Quiz Test

What is g[1][2] in this grid?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.