-4

How to initialize static 2d array

I am trying to initialize static 2d array by statment 'static int b[n][m]={}' , it is showing error, while on giving const parameters, it's working 'static int b[2][10]={}'

#include<iostream>

using namespace std;

void a(int c, int n, int m){
static int b[n][m]={};
// static int b[2][10]={}; , here it is working fine
for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
        b[i][j] = i+j;
    cout<<b[i][j]<<" ";
    }
}

}

int main(){

int c;
cin>>c;
a(c,2,10);
    cout<<endl;
return 0;
}
Ut42
  • 1
  • 1
  • 1

1 Answers1

0

you already initialized your array by 0.

if you whant initialize to something else try this

static int ar[2][3]={{1,2,3},{4,5,6}};

Alexandr
  • 154
  • 1
  • 7