realloc函数作用是扩容。
代码如下:
#include<stdio.h>
#include<stdlib.h>
int main()
{
char* str = malloc(4);
str[0] = 'a';
str[1] = 'b';
str[2] = 'c';
str[3] = 'd';
str = realloc(str, 6);//6表示扩到6个字节
str[4] = 'e';
str[5] = '\0';
printf("%s\n", str);
free(str);
return 0;
}