C Tutorial/stdlib.h/free — различия между версиями

Материал из C\C++ эксперт
Перейти к: навигация, поиск
м (1 версия: Импорт контента...)
 
(нет различий)

Версия 17:21, 25 мая 2010

free

Item Value Header file stdlib.h Declaration void free(void *ptr); Return returns the memory to the heap.


<source lang="cpp">#include <stdlib.h>

 #include <stdio.h>
 int main(void)
 {
   char *str[100];
   int i;
   for(i=0; i<100; i++) {
     if((str[i] = malloc(128))==NULL) {
       printf("Allocation Error\n");
       exit(1);
     }
     gets(str[i]);
   }
   /* now free the memory */
   for(i=0; i<100; i++){
       free(str[i]);
   }
   return 0;
 }</source>