LinguagemC

Realloc_Pointer

Aug 24th, 2016
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // student name Naelson c/c++ advanced !
  2. // Date 2016/12/08
  3. #include <iostream>
  4. #include <stdlib.h>
  5. #include <string.h> // directory of strcpy;
  6.  
  7.     using namespace std;
  8.  
  9. int main(){
  10.    
  11.    char *ptr;
  12.    ptr =  (char* )malloc(1); //allocated one bits of memory for pointer ptr.
  13.  
  14.    strcpy(ptr ,"GameOver");
  15.  
  16.    cout<<*ptr<<"\n"<<&ptr<<endl;
  17.  
  18.    realloc(ptr,8); //reallocating new size of memory.
  19.  
  20.    free(*ptr); //deallocated the memory
  21.  
  22.    return 0;
  23. }
Add Comment
Please, Sign In to add comment