办手机银行有什么坏处:realloc函数怎么用啊?
来源:百度文库 编辑:中科新闻网 时间:2024/09/30 19:44:29
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);
}