int main()
{
int (*Buffer)[3][4]; // Note the brackets around the name- IMPORTANT!
// Also note that the first array element is missing.
int x, y, z;
printf("Starting.....\n");
// Below we allocate memory for the array:
if (!(Buffer = new int[2][3][4])) { printf("Error allocating memory...\n"); return 1; }
// Below we fill the array with data:
for ( x=0; x<2; x++ )
{
for ( y=0; y<3; y++ )
{
for ( z=0; z<4; z++ )
{
Buffer[x][y][z] = x * 100 + y * 10 + z;
}
}
}
//Below we read out the data from the array & print to screen:
for ( x=0; x<2; x++ )
{
for ( y=0; y<3; y++ )
{
for ( z=0; z<4; z++ )
{
printf(" %d ", Buffer[x][y][z] );
}
}
}
// Below we deallocate the memory for the array:
delete [] Buffer;
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.