I have the following code that is supposed to create a new array with the number of elements specified in the parameter...
void *newArray(int nElements){
int *array = NULL;
array = (int *)malloc(nElements * sizeof(int));
if(array == NULL){
printf("Insufficient memory space.\n");
return -1;
}
//Set all values to 0
for(int i = 0; i < nElements; i++){
array[i] = 0;
}
return array;
}
This function returns a generic pointer to an array of type integer with all its values started at 0. But when I invoke the call to this function...
int *array = NULL;
array = (int *)newArray(5);
Throws me the following warning:
main.c:24:16: warning: incompatible integer to pointer conversion returning 'int' from a function with result type 'void *' [-Wint-conversion]
and if I try to print the contents of the array print me two 0. I'm still getting familiar with the C language and I don't really understand what that warning means and how I can fix it so that the function returns me an array with 5 elements in that case.