Hi
Im having a problem when it comes to dynamic memory allocation.I have a program that lets me pick the size of my array,and then input numbers into it.
That all works well,it is when I try to add another int to this array that im having problems with,could anyone shed some light or point me in the right direction..
#include <iostream>
using namespace std;
int main(){
int size;
int* ptr;
cout << "How big is your array going to be?";
cin >> size;
// Enter numbers into array.
for(int i = 0; i < size; i++)
{
cout << "Enter Number: ";
cin >> ptr[i];
}
cout << "Numbers entered into array are: " << endl;
for(int i = 0; i < size; i++){
cout << ptr[i] << endl;
}
// Now i want to add more number to this array.
int newNum = 3;
*(ptr+4) = newNum;
cout << "New array looks like:"<<endl;
for(int i = 0; i < 4; i++){
cout << ptr[i] << endl;
}
return 0;
}