가능한 중복 :
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);
}
우리가 어떻게 (FUNC 메모리 포인터 P에서 메모리 크기를 찾을 수 있습니다)?
malloc (10)은 malloc (10 * sizeof (int))이어야합니다. –