这啥情况运行成功但是这是啥情况,如下图


#include <iostream>
using namespace std;
void rowSum(int a[][4], int nRow) {
    for (int i = 0; i < nRow; i++)
    {
        for (int j = 1; j < 4; j++)
        {
            a[i][0] += a[i][j];
        }
    }

}
int main()
{
    int table[3][4] = { {1,2,3,4},{2,3,4,5},{3,4,5,6} };
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 4; j++)
            cout << table[i][j] << " ";
        cout << endl;
    }
    rowSum(table, 4);
    for (int i = 0; i < 3; i++)
        cout << "Sum is row" << i << "is" << table[i][0] << endl;
    return 0;
}

img

img

数组定义长度为4,他的角标应该是零到四,在我们java中会抛出indexoutofboundsexception角标越界异常

只有3行你nRow传个4,肯定越界了啊

你的二维数组是3.4,调rowSum传的4

第23行,nRow=4,在函数中i会取到3,下标越界,RE了。