search

Home  >  Q&A  >  body text

c++ 二维数组取值,报错 Signal: SIGSEGV (Segmentation fault)

bool isLine(int map[][4]) {
    for (int i = 0; i < 4; i++) {

        for (int j = 0; j < 4; j++) {
            cout <<  map[i][j] << ' ' ;
        }
        cout<<endl;
    }
    if (map[3][0] * map[2][1]* map[1][2] * map[0][3] == 1) return 1;

//*
//*
//*执行到这行时报错,Signal: SIGSEGV (Segmentation fault)
//*
//*
    if (map[0][0] * map[1][1] * map[2][2] * map[3][3] == 1) return 1;


    for (int row = 0; row < 4; row++) {
        if (map[row][0] *map[row][1]* map[row][2]* map[row][3] == 1) return 1;
    }
    for (int col = 0; col < 4; col++) {
        if (map[0][col] * map[1][col]* map[2][col] * map[3][col]) return 1;
    }
    return 0;
}

如代码所示,求解

大家讲道理大家讲道理2804 days ago919

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 15:38:42

    It depends on the specific parameters passed in at the call point and how they are constructed. You have to post the calling code as well.

    reply
    0
  • 阿神

    阿神2017-04-17 15:38:42

    For a two-dimensional array, the first parameter does not need to be specified. The system can obtain the first-dimensional parameter based on the total size and the second-dimensional parameter specified when the array is initialized. This is a segfault. It should be the parameter you passed. There is a problem with the size of the parameter space. The space is too small, so that the one-dimensional parameter cannot reach 3.

    reply
    0
  • Cancelreply