We had learnt to initialize 2D array like this:
int a[100][100] = {0};
int rows,cols;
cin>>rows>>cols;
for (int i=0; i<rows; i++){
for (int j=0; j<cols; j++){
cin>>a[rows][cols];
}
}
But in this video of finding max sum submatrix, they have used something like this:
int main(int argc, char const *argv[]){
int n,m;
cin>>n>>m;
int **arr = new int*[n];
for (int i=0; i<n; i++){
arr[i] = new int[m];
}
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
cin>>arr[i][j];
}
}
}
My question:
- why is argc, char const* argv passed in main function? What does it mean?
- why is array defined as int **arr = new int *[n]
- what is the significance of for loop after the int **arr line?
- in the second for loop, why is " j<n " (and not m), when m is the number of colums?
Can you please help with the above?