C/C++通过指针得到数组大小 引入<malloc.h>头文件,使用其中的_msize()函数得到数组的字节数,再除以sizeof(type)即可。 int* a; a = (int*)malloc(sizeof(int) * 6); cout<< _msize(a)/sizeof(a[0]);