在 main() 之外定义数组的 C++ 问题

问题描述

当我在两个不同的地方定义数组(具有相同的行)时,我找不到以下代码不起作用的原因。这是否是好的做法不是我的问题。我只是想找出原因。


// Array Test: t.cpp
// If only the ONE LINE in question is enabled in either place
// it works/fails as indicated. I wonder why?

#include "iostream"

int a = 5; // Rows
int b = 4; // Columns

// int x[a][b]; // if done here: NoGo! WHY? <<<***************************

int main () {

int x[a][b]; // if done here: OK!           <<<***************************

for (int r = 0; r < a; r++) {
    for (int c = 0; c < b; c++) {
        x[r][c] = (r*10+10) + (c+1);
        std::cout << x[r][c] << " ";
    }
    std::cout << "\n";
  }
std::cout << "\nARRAY CREATED \n\n";
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)