Code::Blocks returns -10737741819 (0xC0000005) 执行嵌套循环时

Code::Blocks returns -10737741819 (0xC0000005) when executing nested loops

我一直在尝试使用嵌套循环将整数插入以下格式的二维数组中:

1, 2, 3, 4, ,5 ,6 ,7 ,8 ,9 ,10

2, 4 ,6 ,8 ,10, 12, 14, 16, 18, 20

3, 6, 9, 12, 15, 18, 21, 24 ,27, 30

...

...

10, 20 , 30 ,40 , 50, 60, 70, 80, 90, 100

我使用以下代码生成结果:

#include <iostream>

using namespace std;

int main() {
    int table[10][10];
    for(int i = 1; i <= 10; i++) {
        for(int j = 1; j <= 10; j++) {
            table[i][j] = (j * i);
            cout << table[i][j] << "\t"<< flush;
        }
        cout << endl;
    }
    return 0;
}

代码运行成功,但在执行过程中出现错误:

我目前正在使用 Code::Blocks + GNU GCC 编译器。 我该如何解决这个问题?是因为我的代码吗?还是编译器?

您应该从 0(含)到 10(不含)开始迭代:

[Try It Online]

#include <iostream>

using namespace std;

int main() {
    int table[10][10];
    for(int i = 0; i < 10; ++i) {
        for(int j = 0; j < 10; ++j) {
            table[i][j] = ((j+1) * (i+1));
            cout << table[i][j] << "\t"<< flush;
        }
        cout << endl;
    }
    return 0;
}

注意:如果使用C++17,可以使用std::size来避免多次硬编码数组大小。 (或者,您可以使用一些特定于编译器的宏。)