Size of dynamic array in C doesn't change

前端 未结 4 1352
我在风中等你
我在风中等你 2021-01-29 02:39

I was getting realloc(): invalid next size for a program. So I just coded this to understand what\'s happening.

#include 
#include &l         


        
4条回答
  •  渐次进展
    2021-01-29 03:16

    sizeof(inp) in your case is sizeof(pointer) and hence sizeof(char-pointer) on your system is 8 bytes which is a constant. While allocating memory using malloc() you would have specified the size so why do you need to get the size of the allocated space again?

    And I see res is being initialized and not inp

提交回复
热议问题