How I return the size of the pointer that I have allocate with malloc?

前端 未结 4 1990
醉酒成梦
醉酒成梦 2021-01-15 03:30

See this example!



int main( int argc, char ** argv )
{
    int *ptr = malloc(100 * sizeof (int));

    printf(\"sizeof(array) is %d bytes\\n\", sizeof(ptr)         


        
4条回答
  •  误落风尘
    2021-01-15 04:21

    Nothing is wrong. You are asking for, and getting, the size of the pointer on your platform.

    It is not in general possible to get the size of the memory block that a pointer points at, you must remember it yourself if you need it later.

提交回复
热议问题