Knowing the size of the array using pointer
问题 How can i know the size of the array using a pointer that is allocated using malloc? #include <stdio.h> int main(){ int *ptr = (int *)malloc(sizeof(int * 10)); printf("Size:%d",sizeof(ptr)); free(ptr_one); return 0; } I get only the size of the pointer in this case which is 8.How to modify the code to get the size of array which will be 40. 回答1: You cannot. You will need to do the bookkeeping and keep track of it yourself. With new you allocate dynamic memory and while deallocating the memory