``````void John_is_3D(int dimx,int dimy,int dimz)
{

int ***John; // pointer to pointer to pointer
John = new int**[dimx]; // array of pointers to pointers

for(int x = 0;x<dimx;x++)
{
John[x] = new int*[dimy];

for(int y = 0;y<dimy;dimz++)
{

John[x][y] = new int[dimz];

for(int z = 0;z<dimz;z++)
{
John[x][y][z]= x*y*z;
cout << John[x][y][z];

}

}
cout <<endl;
}

}
``````

can someone please point out whats wrong in here. I should dynamicly alloc 3d array and fill it with multiplication table

Other than poor formating, I don't see anything wrong with how you allocated the array. The values in the array are something else.

``````void John_is_3D(int dimx, int dimy, int dimz)
{

int ***John; // pointer to pointer to pointer
John = new int**[dimx]; // array of pointers to pointers

for (int x = 0; x<dimx; x++)
{
John[x] = new int*[dimy];
for (int y = 0; y<dimy; dimz++)
{
John[x][y] = new int[dimz];
for (int z = 0; z<dimz; z++)
{
John[x][y][z] = x*y*z;
cout << John[x][y][z];

}

}
cout << endl;
}

}
``````

then why when I run program all I get is endless 0's ?

then why when I run program all I get is endless 0's ?

Simple math says that many of the cells will contain 0 since x, y, or z will be 0, and 0 times anything results in 0. However, there's a bug in the code:

``````for (int y = 0; y<dimy; dimz++)
``````

Notice the increment step modifies `dimz` rather than `y`.

line 15 of the code you posted is wring.

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.