如何为int(* a)[2]分配内存? [英] How to allocate memory to int (*a)[2]?

查看:181
本文介绍了如何为int(* a)[2]分配内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将内存分配给整数类型(* a)[2]?我很乐意使用** a,* a等等等,也可以使用* a [2],但这看起来有所不同。

How do I allocate memory to integer type (*a)[2] ? I am comfortable doing it with **a, *a etc. etc., also *a[2], but this looks different.

有人可以帮忙吗?

推荐答案

与任何指针类型相同,例如您拥有

Same as for any pointer type, say you have

int (*a)[2];

指针 a 指向2个数组的指针 int ,然后分配

a pointer a to arrays of 2 int, then you allocate

a = malloc(number_of_rows * sizeof *a);

获得 number_of_rows *(2 * sizeof(int))的块字节。

然后使用

a[i][j]

0 <=我< number_of_rows 0< = j< 2

这篇关于如何为int(* a)[2]分配内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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