Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. using namespace std;
  5.  
  6. int* AllocateDynamicMemory(int size) {
  7. int* dynamicArray = new int[size];
  8.  
  9.  
  10. return dynamicArray;
  11. }
  12.  
  13. void PrintDynamicArray(int* Array,int size)
  14. {
  15. for(int i = 0; i < size; i++)
  16. {
  17. cout << *Array++ << " ";
  18. }
  19. }
  20.  
  21. void FillDynamicArray(int* Array, int size)
  22. {
  23. for (size_t i = 0; i < size; i++)
  24. {
  25. *(Array + i) = rand() % 100;
  26. }
  27. }
  28.  
  29. void DeleteDynamicMemory(int* memory)
  30. {
  31. delete[] memory;
  32.  
  33. cout << " Memory DeAllocated " << endl;
  34. }
  35.  
  36.  
  37. int main()
  38. {
  39. int size = 10;
  40.  
  41. int* Array = AllocateDynamicMemory(size);
  42.  
  43. FillDynamicArray(Array, size);
  44.  
  45.  
  46. cout << " Press Enter to Delete Array " << endl;
  47. cin.get();
  48. DeleteDynamicMemory(Array);
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. cin.get();
  59. cin.get();
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement