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 ....
creating a 2d array using freestore
# 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++ ;
}
}
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.