few corrections:
line 4,30 : int* allocate(int* array, int size)
explanation: Since you are returning an array after you have allocated enough heap memory,you should return the base address of the array.
Also line 11 :array = allocate(&array[0], 100);
can be wriiten as : array = allocate(array, 100); // Since &(array[0]) is always same as array(i.e base address of array is always same as adress of the 0th element of array)
Line 12 :enterValues(&array, size);
should be corrected to : enterValues(array, size);
Since type of "&array" is int** and its not what is supposed be passed to entervalues () function Enter values expects a int*
Corrected prog:
#include <stdio.h>
#include <stdlib.h>
int* allocate(int*, int);
int enterValues(int*, int);
int main()
{
int *array, size = -1;
array = allocate(&array[0], 100);
printf("Address of the memory space:\n%p\n\n", &*array);
if(array == NULL)
{
printf("Error! memory not allocated.");
exit(0);
}
printf("Enter the size of the array:\n");
scanf("%d", &size);
enterValues(array, size);
for (int i = 0; i < size; i++) {
printf("%d", *(array + i));
}
return 0;
}
int* allocate(int* array, int size)
{
array = (int*) calloc(size, sizeof(int));
return &array[0];
}
int enterValues(int* array, int size)
{
printf("Enter values:\n");
for (int i = 0; i < size; i++) {
scanf("%d", &*(array + i));
printf("%d", *(array + i) ); //<-- I think this is where the error is coming from
}
return 0;
}