Program to get and display 2d array using pointers

  c++, multidimensional-array, pointers

I have created a program to get and display two 2d arrays, and it is working properly but at the end of the program I’m getting an error in my program.

Error:-

Process finished with exit code -11.

Can anyone tell why this error occurs?

My code:-

#include <iostream>
using namespace std;

int ro1,co1,ro2,co2;
int i,j,k;
int *a,*b;

int get1(){
  cout<<"1st array:n";
  cout<<"Number of Rows= ";
  cin>>ro1;
  cout<<"Number of Columns= ";
  cin>>co1;
  
  a=new int[ro1*co1];
  cout<<"Enter array elements:n";
  for (i=0;i<ro1;i++){
    for(j=0;j<co1;j++){
      cin>>*((a+i*co1)+j);
    }
  }
}

int get2(){
  cout<<"2nd array:n";
  cout<<"Number of Rows= ";
  cin>>ro2;
  cout<<"Number of Columns= ";
  cin>>co2;
  
  b=new int[ro2*co2];
  cout<<"Enter array elements:n";
  for (i=0;i<ro2;i++){
    for(j=0;j<co2;j++){
      cin>>*((b+i*co2)+j);
    }
  }
}

int main()
{   
    get1();
    get2();
    
    for (i=0;i<ro1;i++){
      for(j=0;j<co1;j++){
        cout<<*a;
        a=a+1;
      }
      cout<<endl;
    }
    
    for (i=0;i<ro2;i++){
      for(j=0;j<co2;j++){
        cout<<*b;
        b=b+1;
      }
      cout<<endl;
    }
    
    delete []a;
    delete []b;
    
    return 0;
}

Output:-

1st array:

Number of Rows= 2

Number of Columns= 3

Enter array elements:

1 2 3

4 5 6

2nd array:

Number of Rows= 3

Number of Columns= 3

Enter array elements:

1 2 3

4 5 6

7 8 9

1st array:

1 2 3

4 5 6

2nd array:

1 2 3

4 5 6

7 8 9

Process finished with exit code -11.

Source: Windows Questions C++

LEAVE A COMMENT