不是动态分配,只是数据类型为unsigned:
v.data = (unsigned *)malloc(size * sizeof(unsigned));
在函数内部分配内存,返回后,在外面释放内存,是ok的。
二次分配内存:
25为需要的总内存:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *str;
/* 最初的内存分配 */
str = (char *) malloc(15);
strcpy(str, "runoob");
printf("String = %s, Address = %p\n", str, str);
/* 重新分配内存 */
str = (char *) realloc(str, 25);
strcat(str, ".com");
printf("String = %s, Address = %p\n", str, str);
free(str);
return(0);
}
具体类型char的:<