Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void main()
  6. {
  7. cout<<"DYNAMIC MEMORY WORK"<<endl;
  8. cout<<"Creating variables."<<endl;
  9.  
  10. int *a = new int;
  11. int *b = new int;
  12. int *c = new int;
  13.  
  14. cout<<endl<<"Enter a: ";
  15. cin>> *a;
  16. cout<<endl<<"Enter b: ";
  17. cin>> *b;
  18. cout<<endl<<"Enter c: ";
  19. cin>> *c;
  20.  
  21. cout<<"a + b = "<<*a+*b<<endl;
  22. cout<<"a + c = "<<*a+*c<<endl;
  23.  
  24. delete a, b, c;
  25.  
  26. cout<<endl<<"Creating an array of arbitary size."<<endl;
  27.  
  28. int *d = new int;
  29.  
  30. cout<<"Set an array size: ";
  31. cin>>*d;
  32.  
  33. int *arr = new int [*d];
  34.  
  35. for (int i = 0; i<*d; i++)
  36. {
  37. cout<<"Inter the "<<i+1<<" member of array: ";
  38. cin>>arr[i];
  39. }
  40.  
  41. cout<<"The array is:";
  42.  
  43. for (int i = 0; i<*d; i++)
  44. cout<<" "<<arr[i];
  45.  
  46. cout<<endl;
  47.  
  48. delete arr;
  49. delete d;
  50.  
  51. system("pause");
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement