c - 了解指针数组
问题描述
我正在做这样的事情;
int main()
{
int *b[2], j;
for (j = 0; j < 2; j++)
{
b[j] = (int *)malloc(12 * sizeof(int));
}
return 0;
}
请告诉我这条指令的真正含义是什么?以及如何将这个指针数组传递给函数以访问诸如此类的值*(B[0]+1),*(B[1]+1)
?
解决方案
int main(void)
{
int *b[2], j; // initialization of an array of pointers to integers (size = 2)
for (j = 0; j < 2; j++) // for each of the pointers
{
b[j] = malloc(12 * sizeof (int)); // allocate some space = 12 times size of integer in bytes (usually 4)
}
return 0;
}
如果您想将此数组传递给函数,您只需传递 b
foo(b);
推荐阅读
- java - Webelement.click() 在 appium 中给出 java.lang.NullPointerException
- hive - 如何在同一个配置单元表中交换分区
- javascript - Json 结构 - 如何在 javascript 中读取这个 JSON 结构?
- java - 在应用程序进入后台时暂停 scheduleAtFixedRate Timer?
- migration - Downtime of volume backed live migration between two compute nodes (different version: liberty-mitaka) is too high
- sql - SQL Server FOREIGN KEY ON DELTE 抛出自定义消息
- javascript - 文本与 gojs 树图中的箭头重叠
- docker - 如何在 Dockerfile 中指定图像是交互式的?
- javascript - ES6 find() 在具有动态 id 的数组中
- javascript - 如何在“lodash”函数(去抖动)回调函数中传递参数?