/* * 2-dimensional matrix on the stack in a contiguous layout. * * Jed Yang */ #include #include #define N 3 #define M 5 int main(void) { //int matrix[N][M]; //int *matrix[N]; int **matrix; matrix = malloc(sizeof(int *) * N); matrix[0] = malloc(M * sizeof(int)); matrix[1] = malloc(M * sizeof(int)); matrix[2] = malloc(M * sizeof(int)); printf("&matrix = %p, sizeof = %li\n", &matrix, sizeof(matrix)); printf("\n"); for (int row = 0; row < N; row++) { printf("&matrix[%d] = %p, sizeof = %li\n", row, &matrix[row], sizeof(matrix[row])); for (int column = 0; column < M; column++) { printf("&matrix[%d][%d] = %p, sizeof = %li\n", row, column, &matrix[row][column], sizeof(matrix[row][column])); } printf("\n"); } return 0; }