This is a code provided at www.cplusplus.com/doc/tutorial/dynamic/. The provided code doesn't work on my computer. I am using Code-Blocks and Microsoft Visual C++ 6.0, and when I change "nullptr" to zero, it works. Is there any problem in the program? Am I missing something?
// rememb-o-matic
#include <iostream>
#include <new>
usingnamespace 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 == nullptr)
cout << "Error: memory could not be allocated";
else
{
for (n=0; n<i; n++)
{
cout << "Enter number: ";
cin >> p[n];
}
cout << "You have entered: ";
for (n=0; n<i; n++)
cout << p[n] << ", ";
delete[] p;
}
return 0;
}