怎么给一分配的内存区域初始化
如何给一分配的内存区域初始化?
大家好!
请教:
如何给一分配的内存区域初始化?
我知道,如果为整型数分配内存区域,如果初始化为零,可以用memset,比如
int *A = new int[100];
memset(A,0,100);则A中的人和元素都背初始化为0.
那么double、long double的类型如何初始化?比如
double* B = new double[100];
B如何初始化?
谢谢!
------解决方案--------------------
或者:
int main()
{
double *d = new double[10];
memset(d, 0, 10*sizeof(double));
int i;
for(i=0; i <10; i++)
cout < <d[i] < <endl;
system( "pause ");
return 0;
}
大家好!
请教:
如何给一分配的内存区域初始化?
我知道,如果为整型数分配内存区域,如果初始化为零,可以用memset,比如
int *A = new int[100];
memset(A,0,100);则A中的人和元素都背初始化为0.
那么double、long double的类型如何初始化?比如
double* B = new double[100];
B如何初始化?
谢谢!
------解决方案--------------------
或者:
int main()
{
double *d = new double[10];
memset(d, 0, 10*sizeof(double));
int i;
for(i=0; i <10; i++)
cout < <d[i] < <endl;
system( "pause ");
return 0;
}