Advertisement
STANAANDREY

meomory-din_alloc

May 20th, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int x[100];
  8. cout<<sizeof(x)<<endl;
  9. int* ptr;
  10. ptr =(int*)malloc(10 * sizeof(*ptr));
  11. cout<<static_cast<bool>(ptr==NULL)<<endl;
  12. for (int i=0;i<10;i++)
  13.     *(ptr+i)=i;
  14.   for (int i=0;i<10;i++)
  15.     cout<<*(ptr+i)<<' ';
  16.     cout<<endl;
  17.     int* ptr2;
  18.     ptr2=(int*)calloc(10,sizeof(int));
  19. cout<<static_cast<bool>(ptr2==NULL)<<endl;
  20. *(ptr2+1)=3;cout<<*(ptr2+1)<<endl;
  21. free(ptr2);
  22. cout<<*(ptr2+1);
  23. ptr=(int*)realloc(ptr,10*sizeof(long));
  24.   return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement