【发布时间】:2012-10-02 23:44:30
【问题描述】:
我有一个结构:
struct numbers_struct {
char numbers_array[1000];
};
struct numbers_struct numbers[some_size];
创建struct后,有一个整数作为输入:
scanf("%d",&size);
我需要使用malloc(size) 并指定数组编号的大小。 (而不是 some_size 使用大小)
在 C 中这样的事情可能吗?
【问题讨论】:
-
C 中没有 VLA,而是使用 calloc
-
@perilbrain:大家对
calloc有什么看法?与malloc的唯一实际区别是它初始化了内存。 -
@JanHudec:- 那么数组呢???
-
@perilbrain:不,C 没有可变长度数组。但问题已经提到
malloc。 -
@JanHudec,VLA 是在 C99 中引入的。