creating a 2d array using freestore

sweetleaf 0 Tallied Votes 104 Views Share

THE program highlights how to create a 2d array in freestore using pointers..
this is my first post so if i commit any fallacies regarding protocol or syntax please forgive me ....

# include <iostream.h>
void main()
{ int **a=new int*[10] ;
  cout<<"ENter the no of arrays : " ;
  int n ;
  cin>>n ;
  int i,p[5],x=0 ; ;
  for(i=0 ; i<n ; i++)
	 { cout<<"ENter the no. of elements in the "<<i+1<<" array :" ;
		cin>>p[x] ;
		a[i]=new int[p[x]] ;
		for (int j=0 ; j<p[x] ; j++)
			{ cout<<"enter : "  ;
			  cin >> a[i][j] ;
			}
		 x++ ;
	 }
	 x=0 ;
	 int j ;
	 for (i=0 ; i<n ; i++)
		{ for(j=0 ; j<p[x] ; j++)
			 { cout<<a[i][j]<<" " ;
				}
			x++ ;
			

		}
}