????realloc?????extern void *realloc(void *mem_address?? unsigned int newsize);
??????????? ??
?????????=??????????*??realloc??????????С??????????μ??С????
?????μ??С????С??????????????μ??СС???????С????????????????????????
????????
????#include <stdlib.h> ??Щ?????????#include <malloc.h>????TC2.0?п??????alloc.h????
????????
???????ж????????????????????????????У?????mem_address?????????????mem_address????????????????????newsize??????С???????????????????β???????·?????????????????????mem_address????????????????????????????????????free???????????·???????????????????????·???洢?????????
?????????
??????????·?????????????????????????????????NULL??
???????
????????治????????????free()??????????????
??????????
????1
????malloc??calloc??free??_alloca ??t???
????#include <stdio.h>
????#include <malloc.h>
????int main(int argc?? char* argv[])
????{
????int i;
????int *pn;
????pn = (int *)malloc(5*sizeof(int));
????for (i = 0; i < 5; i++) {
????pn[i] = i;
????printf("%d "??pn[i]);
????}
????printf(" ");
????pn = (int *)realloc(pn?? 10*sizeof(int));
????for (i = 5; i < 10; i++) {
????pn[i] = i;
????}
????printf("all data ");
????for (i = 0; i < 10; i++) {
????printf("%d "??pn[i]);
????}
????printf(" ");
????char *p?? *q;
????p = (char *)malloc(10);
????q = p;
????p = (char *)realloc(p??1000);
????printf("%x "??p);
????printf("%x "??q);
????char *m?? *n;
????m = (char *)malloc(10*sizeof(char));
????n = m;
????m = (char *)realloc(m??10*sizeof(char));
????printf("%x "??m);
????printf("%x "??n);
????}
???????н????
????realloc??????????#include<malloc.h> voidmain() { char*p??*q; p=(char*)malloc(10); q=p; p=(char*)realloc(q??20);//A?У????realloc????p?????????μ????????p?? //………………………… }????γ??????????????????q?????????????????????p????γ????????????????????е?A????????????????????????佫??п?????????????????′?С?????realloc????????????????????棬?????????????????????????????????????q?????????????????????????????!?????????q???????????????????????????з?????????????棬???????q?????в???????????????????????????????realloc?????????????????????????
??????????? ??????????void???????????ó??????????????????????????????????????
????????NULL?????????????С??????????????0???????????????NULL????????????“free??????”?????
????????NULL????????????????????????????????????С??????
??????????
??    1. realloc???????????NULL
????2. realloc??????????????治??????????????????
????3. ??????????????滹????????????????realloc?????=????????+?????棬realloc????????????????; ????????????????????????????????realloc???????μ???棬???????????????????????????????????潫??free???realloc????????????
????4. ???size?0??Ч???????free()????????????????????????????????????????**a????a????realloc??????????????????????й???
????5. ?????realloc????????????????malloc()?? calloc()?? ??realloc()?????
????6.?????realloc?????????????????malloc??