Dynamic Memory Allocation Question(simple I'm sure)

Hi, I'm a novice programmer and I'm reading about Dynamic Memory Allocation from the cplusplus.com lessons and I copied the code from the page to play with it and practice. I built and ran the program, and I entered 999999999999 for how many numbers I wanted to enter. The result was "Enter a number:" flashing in my cmd window over and over very quickly like the matrix screensaver. It never gives any error message or stops.

My question is: what exactly is going on here and why? I'm just curious to learn the core of programming and have a good understanding.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// rememb-o-matic
#include <iostream>
#include <new>
using namespace std;

int main ()
{
  int i,n;
  int * p;
  cout << "How many numbers would you like to type? ";
  cin >> i;
  p= new (nothrow) int[i];
  if (p == 0)
    cout << "Error: memory could not be allocated";
  else
  {
    for (n=0; n<i; n++)
    {
      cout << "Enter number: ";
      cin >> p[n];
    }


Thank you,
Wiz.
The problem is that 999999999999 is a big number for an int variable i dont remember what's the limit value for an int variable you should use some modifier like long.
Yes, thank you very much that was really simple I didn't realize that would happen from the data type, but sure enough long did the trick.
Topic archived. No new replies allowed.