#include <iostream>
using namespace std;
int main() {
int rows = 10;
int cols = 9;
int opt[rows][cols] = {0};
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
std::cout << opt[i][j] << " ";
}
std::cout << "\n";
}
return 0;
}
输出:
0 32767 1887606704 10943 232234400 32767 1874154647 10943 -1
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
我正在使用gcc 6.3,在https://www.codechef.com/ide
我希望第一行都是零。这不应该是这种情况吗?
编辑:我测试了行和列的常量变量,然后它初始化为全零。我觉得这应该抛出编译错误,而不是展示这种不正确(并且可能危险)的行为。
int opt[rows][cols]
不是有效的 C++ 代码 - 数组大小必须是编译时常量,而不是变量。 - user2100815