C错误:类型'int *'和'unsigned int'到二进制'运算符*'的操作数无效|

问题描述:

所以,我在C函数中得到这个错误。C错误:类型'int *'和'unsigned int'到二进制'运算符*'的操作数无效|

变量:

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); 

这是一个功能:

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); 
    } 
} 

请帮助!

错误:

invalid operands of types 'int*' and 'unsigned int' to binary 'operator*'|

+0

'int * arr' - >'int ** arr'因为它不反映变化。 – BLUEPIXY 2013-05-05 16:44:32

使用*num代替num中:

realloc(arr, num * sizeof(int)); 

num是指向int,所述int指针对象的值是*num

而且您不应该投下realloc返回值。

http://c-faq.com/malloc/mallocnocast.html