如何分配二维数组指针**? [英] how to assign two dimensional array to **pointer ?

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

问题描述

如何分配二维数组指针**?
这是我所想要做的想法

how to assign two dimensional array to **pointer ? this is the idea of what i want to do

int arrray [2][3];
int **pointer = array;
so pointer[0][1]= 1;

所以任何帮助?
在此先感谢

so any help ? thanks in advance

推荐答案

简单的答案是,你不能。一个二维阵列是持有各个行存储器的连续块,而一个指针的指针可以指内存位置的指针含有整数的不同的存储位置是

The simple answer is that you cannot. A bidimensional array is a contiguous block of memory that holds each line, while a pointer to pointer can refer to a memory location where a pointer to a different memory location containing the integers is.

可以另一方面创建包含指针在您想要的方式的元件的单独的数据结构(即创建一个指针数组,初始化这些指针的每一行的开始,并使用一个指针指针数组作为指针),但它是没有作用的,而是将一切unneedingly复杂。

You can on the other hand create a separate data structure that holds the pointers to the elements in the way you want (i.e. create an array of pointers, initialize those pointers to the beginning of each row, and use a pointer to that array of pointers as pointer), but it is not useful at all, but rather will complicate everything unneedingly.

问题很可能来自常见的误解是数组和指针是的相同的,他们不是。阵列可以衰减到的指针数组的第一元素(和将这样做往往),但该指针的类型是第一个元素的类型。在一个二维阵列,所述第一元素的类型是内阵列,而不是基本元素类型

The question probably comes from the common misconceptions that arrays and pointers are the same, which they are not. An array can decay to a pointer to the first element of the array (and will do so quite often), but the type of that pointer is the type of the first element. In a bidimensional array, the type of the first element is the inner array, not the basic element type.

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

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