C语言——创建动态二维数组

int main() {
    int **a;
    int row, column;
    int count = 0;
    scanf("%d%d", &row, &column);
    a = (int **)malloc(row * sizeof(int *));
    for (int i = 0; i < row; i++) {
        a[i] = (int *)malloc(column * sizeof(int));
    }

    for (int y = 0; y < row; y++) {
        for (int x = 0; x < column; x++) {
            a[y][x] = count++;
            printf("%d ", a[y][x]);
        }
        printf("\n");
    }
}

 

posted on 2021-02-01 21:05  平ping  阅读(489)  评论(0)    收藏  举报