I am trying to allocate space for 100 integers. But end up with 2 and have not a clue why! I tried both malloc()
and calloc
but understandingly there is no difference.
Code:
#define MAX 100
int *arr = (int *)calloc(MAX, sizeof(int)); //same with malloc(MAX * sizeof(int))
printf("MAIN before memset: %d | %d\n",
(int)(sizeof(arr)/sizeof(arr[0])), (int)(sizeof(arr)));
if(!arr) {
fprintf(stderr, "A malloc error occured.\n");
exit(1);
}
memset (arr, 0, MAX);
printf("MAIN: %d\n", (int)(sizeof(arr)/sizeof(arr[0])));
OUTPUT:
MAIN before memset: 2 | 8
MAIN: 2
What am I coming short of? I simply want to allocate an array/pointer to 100 integers.