realloc函数怎么用啊?

来源:百度知道 编辑:UC知道 时间:2024/04/25 06:07:38
realloc函数怎么用啊?最好写一个小程序,谢啦

动态分配内存空间,原型:
void *realloc( void *memblock, size_t size );

例子:
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>

void main(void)
{
char* ptr = NULL;

realloc(ptr, 5);
assert(ptr != NULL);
strcpy(ptr, "abcd");
puts(ptr);
free(ptr);
}

看看吧

http://www.zahui.com/html/1/3573.htm