Tutorial by Examples

Passing a 2d array to a functions seems simple and obvious and we happily write: #include <stdio.h> #include <stdlib.h> #define ROWS 3 #define COLS 2 void fun1(int **, int, int); int main() { int array_2D[ROWS][COLS] = { {1, 2}, {3, 4}, {5, 6} }; int n = ROWS; int m...
Often the easiest solution is simply to pass 2D and higher arrays around as flat memory. /* create 2D array with dimensions determined at runtime */ double *matrix = malloc(width * height * sizeof(double)); /* initialise it (for the sake of illustration we want 1.0 on the diagonal) */ int x, y...

Page 1 of 1