![](/img/trans.png)
[英]Error - Subscripted value is neither array nor pointer nor vector in C
[英]error: subscripted value is neither array nor pointer nor vector in C
the_project.c:73:22: error: subscripted value is neither array nor pointer nor vector
它给出了上面的错误,下面是第73行。
customer_table[my_id][3] = worker_no;
我声明了全局数组如下
int *customer_table; //All the info about the customer
此代码行不在main函数中。 我主要为此全局数组分配内存。 这可能导致此问题吗?
您正在声明一个pointer-to-int
的pointer-to-int
。 因此cutomer_table[x]
是一个int,而不是一个指针。 如果需要二维动态分配的数组,则需要:
int **customer_table;
而且您在分配时需要非常小心。
(有关示例,请参见例如2D char数组的动态内存 。)
问题是customer_table[my_id]
不是指针或数组,因此不能在其上使用[]
。
注意,由于customer_table
是一个指针,因此使用[]
的第一个取消引用是可以的。 一旦应用了第一个[]
它就会变成一个int
。
也许您真正想要使用的是
int **customer_table;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.