求助关于int类型的**P内存分配与释放(已解决~谢谢)
#include <iostream.h>
int main(){
const sizeX = 4;
const sizeY = 3;
int **p;
//为**p分配4*3的内存;
p = new int[sizeX];
for(int i = 0 ;i < sizeX; i++){
p[i] = new int[sizeY];
}
//赋值
for(int x = 0; x < sizeX ; x++)
for(int y = 0;y < sizeY ; y++)
*((p+x*sizeX) + y) = x*y;
//打印
for( int z = 0; z < sizeX ; z++)
for(int a = 0;a < sizeY ; a++)
cout << *((p+z*sizeX) + a) << endl;
//释放内存
for(int b = 0 ; b < sizeX ; b++)
delete [] p[b];
delete [] p;
return 0;
}
不知道那里错误了~~请大侠们帮我改改~~能把数组的改成指针类型最好不过了~~
[此贴子已经被作者于2007-10-24 10:48:16编辑过]