0
./product -rows 4 -cols 4

次のエラーが表示されます。

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Abort (core dumped)

そして、これは私のコードです..

#include <iostream>
#include <stdlib.h>

using namespace std;


int **create_array(int rows, int cols){
   int x, y;
   int **array = new int *[rows];
    for(int i = 0; i < cols; i++){
       array[i] = new int[cols];
    }
    array[x][y] = 1+rand()%100;
    cout << array << endl;
    return array;
}  
int main(int argc, char *argv[]){
    int rows, cols;
    int **my_array = create_array(rows, cols);

    return 0;
}
4

1 に答える 1