Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何为整数类型 (*a)[2] 分配内存?我很乐意使用 **a、*a 等,还有 *a[2],但这看起来不同。
有人可以帮忙吗?提前致谢。
与任何指针类型相同,假设您有
int (*a)[2];
指向a2 数组的指针int,然后分配
a
int
a = malloc(number_of_rows * sizeof *a);
获取一个number_of_rows * (2 * sizeof (int))字节块。
number_of_rows * (2 * sizeof (int))
然后你访问它
a[i][j]
和。0 <= i < number_of_rows_0 <= j < 2
0 <= i < number_of_rows
0 <= j < 2