Calloc二维数组 [英] Calloc a Two-Dimensional Array

查看:132
本文介绍了Calloc二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要制作一个二维数组,我目前正在使用以下内容:

To make a two dimensional array, I'm currently using the following:

int * own;

own = (int *)calloc(mem_size, sizeof(int));

for (i=0;i<mem_size;i++){
    own[i] = (int *)calloc(3, sizeof(int));
}

但是,每次我引用own [i] [j]时,都会收到一条错误消息,说下标值既不是数组,也不是指针,也不是向量.

However, every time I reference own[i][j], I get an error saying that the subscripted value is neither array nor pointer nor vector.

推荐答案

使用:

int ** own; // int**, not int*
own = calloc(mem_size, sizeof(int*)); //int*, not int
                                      // And remove the explicit cast.

这篇关于Calloc二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆