fork download
  1. //Cecilia Rangel CSC5 Chapter 9, P.537, #1
  2. //
  3. /**************************************************************
  4.  *
  5.  * COMPUTE ARRAY ALLOCATOR
  6.  * ____________________________________________________________
  7.  * This program will dynamically allocate an array of intergers
  8.  * the function accepts an integer argument to allocate and
  9.  * returns a pointer value.
  10.  *
  11.  *_____________________________________________________________
  12.  * INPUT
  13.  * SIZE : INPUT the the number of
  14.  * elements to allocate
  15.  *
  16.  * OUTPUT
  17.  * ptr : OUTPUT pointer for the location
  18.  * of allocated memory
  19.  * ***************************************************************/
  20. #include <iostream>
  21. #include <iomanip>
  22. using namespace std;
  23.  
  24. int main() {
  25. int SIZE;
  26. cout << "Enter the number of elements in the array.\n";
  27. cin >> SIZE;
  28. int* ptr;
  29. ptr = new int[SIZE];
  30. cout << "The allocated address of ptr is :" << ptr << endl;
  31. ptr = new int[SIZE];
  32. cout << "The new allocated address of ptr is :" << ptr << endl;
  33. return 0;
  34. return 0;
  35. }
Success #stdin #stdout 0s 544KB
stdin
15
stdout
Enter the number of elements in the array.
The allocated address of ptr is :0x561680a28e90
The new allocated address of ptr is :0x561680a28ee0