[英]C error: invalid operands of types 'int*' and 'unsigned int' to binary 'operator*'|
So, I get this error in C function. 因此,我在C函数中收到此错误。
Variables: 变量:
int* first_array = (int*) malloc(0);
int first_array_length;
int* second_array = (int*) malloc(0);
int second_array_length;
// Setting up first array
set_up_array(first_array, &first_array_length);
And this is a function: 这是一个函数:
void set_up_array(int *arr, int *num)
{
char lenght_msg[] = "Iveskite masyvo ilgi";
char value_msg[] = "Iveskite masyvo elementa";
*num = num_scan(0, MAX_SIZE, lenght_msg);
arr = (int*) realloc(arr, num * sizeof(int)); // <- error here
for (int i = 0; i < (*num); i++)
{
arr[i] = num_scan(INT_MIN, INT_MAX, value_msg);
}
}
Please, help! 请帮忙!
Error: 错误:
invalid operands of types 'int*' and 'unsigned int' to binary 'operator*'| 类型为'int *'和'unsigned int'的无效操作数为二进制'operator *'|
Use *num
instead of num
in: 使用*num
代替num
in:
realloc(arr, num * sizeof(int));
num
is a pointer to int
, the value of the int
pointee is *num
. num
是一个指针int
,所述的值int
指针对象是*num
。
And you should not cast the realloc
return value. 并且您不应该realloc
返回值。
http://c-faq.com/malloc/mallocnocast.html http://c-faq.com/malloc/mallocnocast.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.