I have the following code:
int *numberArray = calloc(n, sizeof(int));
And I am unable to understand why I receive the following error.
Syntax for calloc is:
void* calloc (size_t num, size_t size);
calloc returns void pointer. In your code , you are trying to assign void pointer to integer pointer. So you are getting Cannot initialize a variable of type 'int *' with an rvalue of type 'void *'. So typecast the void pointer before assign it like this
*numberArray = (int *) calloc(n, sizeof(int));