标签: c pointers allocation
我正在寻找一种方法来获取指针地址的数组长度。 一个例子:
int *a = (int*)malloc(sizeof(int)*2);// will be an array. *(a+0) = 1; // values of the array *(a+1) = 2;
有没有办法检测此指针分配了多少内存?我们建议此数组中没有空元素。如果我知道分配了多少内存,我应该能够获得一个数组的大小(以sizeof(int)为单位);