简体   繁体   English

C错误:类型为'int *'和'unsigned int'的无效操作数为二进制'operator *'|

[英]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.

相关问题 类型&#39;int *&#39;和&#39;long unsigned int&#39;类型的无效操作数到C中的二进制&#39;operator *&#39;错误 - invalid operands of types ‘int*’ and ‘long unsigned int’ to binary ‘operator*’ error in C 错误消息:“float”和“int”类型的无效操作数转换为二进制“operator%” - Error Message : Invalid operands of types 'float' and 'int' to binary 'operator%' 错误,“对二进制 * 的操作数无效(有“long unsigned int”和“int *”)” - Error, 'invalid operands to binary * (have 'long unsigned int' and 'int *')' C 编程错误 二进制 int 和 long long 无符号操作数无效 integer - C Programmıng Error invalid operands to binary int and long long unsigned integer 错误:二进制+的无效操作数(有'int *'和'int *')| - error: invalid operands to binary + (have 'int *' and 'int *')| 错误:二进制 * 的无效操作数(有 'int' 和 'int *') - error: invalid operands to binary * (have 'int' and 'int *') 错误:二进制 + 的操作数无效(有 'int *' 和 'int *') - error: invalid operands to binary + (have ‘int *’ and ‘int *’) 二进制 &amp; 的错误操作数无效(有 'int **' 和 'int *') - Error invalid operands to binary & (have 'int **' and 'int *') 错误:二进制 * 的无效操作数(有 'int *' 和 'int') - error: invalid operands to binary * (have ‘int *’ and ‘int’) 二进制错误的无效操作数(有&#39;long unsigned int *&#39;和&#39;int&#39;) - Invalid operands to binary errors (have 'long unsigned int *' and 'int')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM