fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6. cout << "How many integers you wish to enter? ";
  7. int InputNums = 0;
  8. cin >> InputNums;
  9.  
  10. int* pNumbers = new int [InputNums]; // Allocate request integers.
  11. int* pCopy = pNumbers;
  12.  
  13. cout << "Successfully allocated memory for: " << InputNums << " integers." << endl;
  14. for (int Index = 0; Index < InputNums ; ++ Index){
  15. cout << "Enter number: " << Index << ": ";
  16. cin >> *(pNumbers + Index);
  17. }
  18.  
  19. cout << "Displaying all numbers input: " << endl;
  20. for(int Index = 0, *pCopy = pNumbers; Index < InputNums; ++Index)
  21. cout << *(pCopy++) << " ";
  22.  
  23. cout << endl;
  24.  
  25. // Done w/using pointers? Release memory.
  26. delete[] pNumbers;
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 3232KB
stdin
Standard input is empty
stdout
How many integers you wish to enter? Successfully allocated memory for: 0 integers.
Displaying all numbers input: