Play and learn 300 000+ tabs online

Monday, August 9, 2010

C++ Dynamic allocation

#include<iostream>
int main()
{
char ***p;
int i,j,r,c;
r = 5, c = 4;
p = new char**[r];
for(i=0;i<r;i++) {
p[i] = new char*[c];
for(j=0;j<c;j++) {
p[i][j] = new char[strlen("Arun") +1];
strcpy(p[i][j],"Arun");
cout<<p[i][j]<<"\t";
}
cout<<"\n";
}
// Cleanup
for(i=0;i<r;i++) {
for(j=0;j<c;j++) {
delete p[i][j];
}
delete p[i];
}
delete p;

}
 
 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.