I have created an array using malloc with the following line of code:
int* array = (int*)malloc(12*sizeof(int));
I attempt to get the size with:
int size = sizeof(array)/sizeof(int);
This returns 2 however, not 12 (I'm aware that sizeof(array[0] is more general.) Confusingly (for me), when I create an array using
int array[12]
the above line of code returns the correct size: 12.
Further, I'm able to fill the int* array with 12 integers without a segmentation fault, which I don't understand if the size turns out to be 2.
Could someone please tell me what I'm doing wrong / how to get the size of an array initialized using malloc in c?
Sorry if this is basic I looked around and couldn't find an answer.
Thanks for your time.