logo

Multidimensional arrays in C

#include <stdio.h> #include <stdlib.h> #include <string.h> void process(int* arr) { // dummy function // NOTE: Just one * since arr is statically allocated } int main(int argc, char* argv[]) { int arr[][3] = { { 2, 7, 10 }, { 12, 22, -20 }, { 11, 5, 15 } }; int i, j; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { printf("%d ", arr[i][j]); } printf("\n"); } // calling a function process(arr); return 0; }
Course thumb

The C programming language made simple