可能重複:
How can I get the size of an array from a pointer in C?
How can I get the size of a memory block allocated using malloc()?查找程序中分配的內存?
void func(int *p)
{
// Add code to print MEMORY SIZE which is pointed by pointer p.
}
int main()
{
int *p = (int *) malloc(10 * sizeof(int));
func(p);
}
,我們如何才能找到內存大小從內存指針P在FUNC()?
malloc(10)應該是malloc(10 * sizeof(int)) –