您的位置:首页 > 其它

动态分配和释放一、二维数组

2012-05-08 11:16 225 查看
分配:

double **a=new double *[2*numPoints];

for(int i = 0; i <2*numPoints;i++)

a[i] = new double[8];

double *b =new double[2*numPoints];

释放:

for(int i = 0; i<2*numPoints;i++)

{

delete [8]a[i];

a[i]=NULL;

}

delete [2*numPoints]a;

delete []b;

a=NULL;

b=NULL;

如下:

float* fInit1DPointer(int num)

{

register int i;

float* p = new float[num];

for(i=0; i<num; i++)

{

p[i]=0.0f;

}

return(p);

}

void Free_f1DPointer(float *p)

{

delete [] p;

}

float** fInit2DPointer(int row,int col)

{

register int i,j;

float* arr = new float[row*col];

float** p = new float*[row];

for(i=0; i<row; i++)

{

p[i] = arr + i*col;

for(j=0; j<col; j++)

{

p[i][j]=(float)0.0;

}

}

return(p);

}

void Free_f2DPointer(float **p)

{

delete [] *p;

delete [] p;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: