C里面动态定义数组?

C里面动态定义数组?

我现在定义的是A[5][5]
后来要加几个元素A[6][6]
动态数组?ArrayList??
如果是指ArrayList的话.

System.Collections.ArrayList NewArr = new System.Collections.ArrayList() ; //定义一个新的数察缺组
object o = new System.Data.DataSet() ; //数组中可以予object以下所有类;
NewArr.Add(o) ; //滑没迹向其中添加.
object oLoad = (object)NewArr[0] ; //读出时还信并原成原类型.
NewArr.Remove(o) ; //移除它.
#include 行正
#include
#define SIZE 128
#define N_SIZE 256
void main(){
int *ptr;
ptr=(int *)malloc(100*sizeof(int));//1
ptr=(int *)realloc(ptr,200*sizeof(int));//2
free(ptr);
}
注;1)malloc (calloc)确保空间 SIZE
2)realloc 在原空间基培御础上增加N_SIZE
一般在前面会有一些对SIZE的判断,配带岩来决定是否增加.
啦队这里就不写啦
这个问题问握慎过多次哗袭了。。。
int *array=(int*)malloc(sizeof(int)*size)
或段芦敬int *array=(int*)calloc(size,sizeof(int))
只能是用链表来实现。
int abc[];
← 上一篇: 下一篇: →