如何动态分配存储器为一个二维阵列 [英] how to allocate memory dynamically for a two dimensional array

查看:156
本文介绍了如何动态分配存储器为一个二维阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直是一个面试,他们要我写一个长期计划了二维数组(I = 3和j = 2)

动态分配内存
解决方案

 为int * A =(INT *)malloc的(我*Ĵ*的sizeof(INT));

您可以得到 A [K] [1] A [K * I + 1];

I had recently been for a interview and they had asked me to write a programe to allocate memory dynamically for a two dimensional array (i=3 and j=2)

解决方案

int *a = (int*)malloc(i*j*sizeof(int));

You can get a[k][l] with a[k*i+l];

这篇关于如何动态分配存储器为一个二维阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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