/* realloc函数的使用 */ |
#include <stdio.h> |
#include <stdlib.h> |
int main( void ) { |
int *p = NULL; |
/* 使用malloc为p分配一个int型空间,并赋值为3 */ |
p = ( int *) malloc ( sizeof ( int )); |
*p = 3; |
printf ( "p = %p\n" , p); |
printf ( "*p = %d\n" , *p); |
/* 使用realloc为p分配一个int型空间 */ |
p = ( int *) realloc (p, sizeof ( int )); |
printf ( "p = %p\n" , p); |
printf ( "*p = %d\n" , *p); |
/* 使用realloc为p分配3个int型空间 */ |
p = ( int *) realloc (p, 3 * sizeof ( int )); |
printf ( "p = %p\n" , p); |
printf ( "*p = %d\n" , *p); |
/* 使用realloc释放p执行的空间 */ |
realloc (p, 0); |
p = NULL; |
return 0; |
} |
by: 发表于:2017-08-21 14:33:34 顶(0) | 踩(0) 回复
??
回复评论