Calcifa97
Calcifa97
2019-12-14 11:42

new定义的三维数组输出出现错误

  • c++

我用new定义三维输出,输出变成十六进制的地址了,定义二维数组则可以正常输出,请问这是怎么回事?

#include <iostream>
using namespace std;
int main()
{
    int i, j, k;
    int X, Y, Z;
    X = 3;
    Y = 4;
    Z = 5;
    int*** max;
    max = new int** [X];
    for (int i = 0; i < X; i++)
    {
        max[i] = new int* [Y];
    }
    for (int i = 0; i < X; i++)
    {
        for (int j = 0; j < Y; j++)
        {
            max[i][j] = new int [Z];
        }
    }
    for (k = 0; k < Z; k++)
    {
        for (j = 0; j < Y; j++)
        {
            for (i = 0; i < X; i++)
            {
                max[i][j][k] = 2;
            }
        }
    }
    for (k = 0; k < Z; k++)
    {
        for (j = 0; j < Y; j++)
        {
            for (i = 0; i < X; i++)
            {
                cout << max[i][j] << "\t";
            }
            cout << endl;
        }
        cout << "----------------------------" << endl;
    }
    return 0;
}

图片说明

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答