I am simply trying to dynamically declare an array in C The code is as follows:
int maxSize = 3;
int *answer;
answer = malloc(maxSize * sizeof(int));
printf("this is max size: %d\n", maxSize);
printf("this is the mult result: %d\n", maxSize * sizeof(int));
printf("size of answer in bytes: %d\n", sizeof(answer));
printf("size of the answer array: %d\n", sizeof(answer) / sizeof(answer[0]));
Printing the result gives me:
this is max size: 3
this is the mult result: 12
size of answer in bytes: 8
size of the answer array: 2
I don't think it's an architecture thing (rather me being inexperienced), but I am running this on a Macbook Pro.
I do not understand why is malloc only allocating 8 bytes instead of 12 bytes for the integer array.