I'm looking at an example of creating a pointer and requesting memory but I don't understand it
I know a pointer points to a certain block in memory but when I'm writing it down and seeing it written down it just confuses me.
This is the example I'm looking at.
#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];
}
cout << "You have entered: ";
for (n=0; n<i; n++)
cout << p[n] << ", ";
delete[] p;
}
return 0;
}
Basically I'm just asking for someone to explain how this works even more because the way I'm reading it on other sites doesn't make any sense to me

New Topic/Question
Reply




MultiQuote






|