如何在用户定义列数的情况下将2D数组传递给函数?(C ++)

时间:2015-11-23 21:27:42

标签: c++ arrays

举例说明我遇到的问题。我做了这个简单的程序,我试着阅读一堆教程并在谷歌搜索我的麻烦,但我只是不明白。

#include<iostream>
using namespace std;

void noobFunction( int col , int table[][col]){ // compile error
   table[0][0] = 2;
   cout << table[0][0];
}

int main() {
   cout << "Enter the number of rows in the 2D array:  ";
   int row;
   cin >> row;

   cout << "Enter the number of columns in the 2D array:  ";
   int col;
   cin >> col; 

   int table[lin][col];

   noobFunction(col, table); 

   return 0;
}

0 个答案:

没有答案