Code:-
    #include <iostream> 
    using namespace std;
    
    int main() {
        int r,c,*p;
        cout<<"Rows : ";
        cin>>r;
        cout<<"Columns : ";
        cin>>c;
        
        p=new int[r*c];
        
        cout<<"\nEnter array elements :"<<endl;
        int i,j,k;
        for( i=0;i<r;i++){
          for( j=0;j<c;j++){
            cin>>k;
            *(p+i*c+j)=k;
          }
        }
        
        cout<<"\nThe array elements are:"<<endl;
        for( i=0;i<r;i++){
          for( j=0;j<c;j++){
            cout<<*p<<" ";
            p=p+1;
          }
          cout<<endl;
        }
        cout<<endl;
        
        delete[]p;
        return 0; 
}
Output:-
Error:-
munmap_chunk(): invalid pointer Process finished with exit code -6.
Can anyone explain why the above error occurs?
 
    