为什么不用5,3而不是3,5?

0 c pointers matrix

我已经编写了这段代码,但我不知道为什么它会因5 3输入而失败.当我给出3 5它工作正常.在每种情况下,如果第二个数字更大,它有效,但为什么呢?我已经用malloc尝试过了.我正在使用Windows 7,代码块10.05

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int **matr;
    int row, col, i, j;

    scanf("%d", &row);    //number of rows
    scanf("%d", &col);    //number of cols

    matr = calloc(col, sizeof(int*));      //creating cols
    for(i = 0; i < col; i++)
    {
        matr[i] = calloc(row, sizeof(int));  //in every col i create an array with the size of row
    }

    for(j = 0; j < row; j++)
    {
        for(i = 0; i < col; i++)
        {
            matr[j][i] = 10;        //fill the matrix with number 10
        }
    }
printf("Matrix is ready\n");

    for(j = 0; j < row; j++)        //printing the matrix
    {
        for(i = 0; i < col; i++)
        {
            printf("%d ", matr[j][i]);
        }
        printf("\n");
     }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

dla*_*ask 5

尝试matr[i][j]而不是matr[j][i].

换句话说,仔细检查索引的顺序及其范围.