This code has failed to answer the question. First, the question asked about using "malloc" not the "new" operator. Second, you have provided faulty code demonstrating that you yourself do not understand the concept. The code you have provided exceeds the bounds of the array you define. The first example being that your first dimension is intialized to hold 2 elements yet you use a bounds of 5 when trying to allocate the second dimension.
Hi tyreId,
Thankx for your comments,
I'm accept my mistake....
I think I was unsure about what I wrote
Also I just provided solution using new coz the thread link already contains solution using malloc and I thought to implement using new....
Never mind thankx for your comments and I think here is the solution you were looking for
- int main(void)
-
{
-
int ***p;
-
p = new int**[5];
-
for(int i=0; i<5; ++i)
-
{
-
p[i] = new int*[5];
-
for(int j=0; j<5; ++j)
-
{
-
p[i][j] = new int[5];
-
}
-
}
-
return 0;
-
}