原帖由 woyaoxuexi 于 2006-3-28 16:56 发表
比如我可以用:
int * shuzu=(int *)malloc(length*sizeof(int));
用上面的语句可以生成一个length长度的一位整形数组,那么怎么生成
一个m*n的二位这个整形数组呢?这里的m和n都是动态得到的值,拜托大虾了
Allocates an array in memory with elements initialized to 0.
Parameters
num
Number of elements.
size
Length in bytes of each element.
Return Value
calloc returns a pointer to the allocated space. The storage space pointed to by the return value is guaranteed to be suitably aligned for storage of any type of object. To get a pointer to a type other than void, use a type cast on the return value.
原帖由 依赛特小子 于 2006-3-29 09:22 发表
int **a=NULL;
a=new int b[];
for(int k=0;k<num;k++)
{
b[k]=new int ;
}
原帖由 hkwang66 于 2006-3-30 03:43 发表
这样代码你也能写出来?
a=new int b[];
原帖由 独孤九贱 于 2006-3-30 09:52 发表
搞不懂,二级数组不就是一维数组吗?和变通的动态内存分配有区别么?偶觉得没有区别……
原帖由 aero 于 2006-3-31 21:56 发表
好像动态开辟的都没办法使用a[m][n]的方法来指定一个元素了吧?因为编译器并不知道抽象的“维度”。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |