首页 > 解决方案 > 这两个语句是什么意思 char (*test)[10]; 测试=新字符[4][10];

问题描述

在 C++ 中

char (*test)[10];

test = new char[4][10];

以上两个声明的含义是什么?

标签: c++pointersmultidimensional-arraydynamic-memory-allocation

解决方案


char (*test)[10];

第一行声明test为指向char[10].

test = new char[4][10];

第二行创建一个char[4][10]具有 4 个类型元素的数组char[10],并将指向该数组第一个元素的指针分配给test

它类似于

 T* test;          // pointer to T
 test = new T[4];  // create array with 4 elements 
                   // and assign pointer to first element to test

推荐阅读