int a[10]
int b[20][10]
類型:
a: int [10]
b: int [20][10]
a, b 都是右值
精確裝換級別類型:
a--->int *
b ---->int (*)[10]
地址類型
&a : int (*)[10]
&b:int (*)[20][10]
問題:如何在堆中動態分配多維數組
思路:降維分配
int ** p;
int a=30;
int b=50;
p=new int * [30];//2維分配
*(p+1)=new int [50];
*(p+2)=new int [50];
一維是連續地址
2維是非連續的
另種思路:結構指針
struct color
{
int * a;
}
color * b;
b=new color[50];
b[1].a=new int [60];
posted on 2008-06-06 10:37
黃大仙 閱讀(704)
評論(0) 編輯 收藏 引用