Advertisement
paulogp

realloc

Jul 19th, 2011
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. // title: realloc
  2. // ide: apple xcode
  3. // author: paulogp
  4.  
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9.  
  10. int main (int argc, const char * argv[])
  11. {
  12.     char *the_str;
  13.    
  14.     // cria a string the_str;
  15.     the_str = (char *) malloc(15);
  16.    
  17.     // coloca a frase "hello world" na string the_str
  18.     strcpy(the_str, "hello world");
  19.    
  20.     printf("string: %s\nEndereco: %p\n", the_str, the_str);
  21.    
  22.     // altera o numero de bytes que estao presentemente associados a
  23.     // um bloco previamente criado utilizando a funcao malloc ou calloc
  24.     the_str = (char *) realloc(the_str, 50);
  25.     printf("string: %s\nEndereco: %p\n", the_str, the_str);
  26.    
  27.     // libertar memoria
  28.     free(the_str);
  29.    
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement