INT指针数组 [英] Array of int pointers

查看:191
本文介绍了INT指针数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到这个问题就来了:

I came across this question:

在下面的声明,p是一个指针至5整数的数组
  指针。

In the declaration below , p is a pointer to an array of 5 int pointers.

为int *(* p)的[5];

int *(*p)[5];

这下面的语句可用于分配内存
  为了第一个维度做的p 5 3数组的数组
  指针为int类型?

which of the following statements can be used to allocate memory for the first dimension in order to make p an array of 3 arrays of 5 pointers to type int ?

一个。 p值=新INT [3] [5] *;

A. p = new int [3][5]*;

乙。 p值=新INT(*)[3] [5];

B. p = new int (*)[3][5];

℃。 p值=新INT [3] * [5];

C. p = new int [3]*[5];

Ð。 p值=新为int * [3] [5];

D. p = new int *[3][5];

电子。 p值=新INT(* [3])[5];

E. p = new int (* [3] ) [5];

答案是什么?

我不知道我理解的问题。通常我会创建一个指向5一个int数组这样为int * P [5]; 我很好奇,为什么他们这样做是为为int *(* p)[5];

I am not sure I understand the question. Normally I would create a pointer to an array of 5 int as such int* p[5]; I am curious as to why they did it as int *(*p)[5];

也做的问题想要什么?难道要求进行初始化(分配内存),以第3 INT指针?我想AP preciate,如果有人可以给我讲解一下

Also what does the question want ? Is it asking to initialize (allocate memory) to the first 3 int pointers ? I would appreciate it if someone could explain this to me

推荐答案

您会为写什么:

int* p[5];

是指针的五行阵 INT

这是什么声明:

int *(*p)[5];

是一个指向指针的五行阵 INT ,即一个指向你刚才写的东西的类型。

is a pointer to a five element array of pointers to int, i.e. a pointer to the type of thing you just wrote.

在换言之;你可以这样做:

In other words; you could do:

int * a[5];
int * (*p)[5] = &a;

您可以心理上逐步阅读如下:

You can mentally read this incrementally as follows:

(*p)               //  p is a pointer
(*p)[5]            //  p is a pointer to an array of size 5
int * (*p)[5]      //  p is a pointer to an array of size 5 of type pointer to int

您需要周围的括号 * P ,因为否则的话:

You need the parentheses around *p, because otherwise:

int ** p[5];

将宣布类型的5元素的数组 INT ** ,或指针的指针的 INT ,这是完全不同的事情。

would declare a 5 element array of type int **, or pointer to pointer to int, which is a different thing entirely.

问题基本上是要求你动态分配内存相当于三个什么样的 A 的正上方,所以回答D是正确的。

The question is basically asking you to dynamically allocate memory equivalent to three of what a is above, so answer "D" is the correct one.

这篇关于INT指针数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆