How can I get the size of an array from a pointer in C?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I've allocated an "array" of mystruct of size n like this: if ( NULL == ( p = calloc ( sizeof ( struct mystruct ) * n , 1 ))) { /* handle error */ } Later on, I only have access to p , and no longer have n . Is there a way to determine the length of the array given just the pointer p ? I figure it must be possible, since free(p) does just that. I know malloc() keeps track of how much memory it has allocated, and that's why it knows the length; perhaps there is a way to query for this information? Something like... int length =