I am busy working on a simple concept to display pointer arrays and iterations of a for loop in C++
My compiler is not giving much away and when I run the program the console is saying the following and returning 3 "The application has requested the Runtime to terminate in an unusual way.
The crash occurs on this line:
cout << i + 1 << " " << *(pArray + i) << endl;
but when I run this program ommiting either i + 1 or *(pArray + i) it runs without errors or crashing.
Is it illegal to try and output as I am trying to do above?
See below for the code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
int * pArray;
int SIZE;
int module;
pArray = new int[SIZE];
cout <<"Enter the number of Assignments ";
cin >> SIZE;
cout <<"input assignment number " ;
for (int i = 0; i < SIZE; i++)
{
cin >> module;
*(pArray + i) = module;
}
// Print array
for (int i = 0; i < SIZE; i++)
{
cout << i + 1 << " " << *(pArray + i) << endl;
}
cout << endl;
delete[] pArray; // Deallocate array via delete[] operator
return 0;
}
I am admittedly a little nervous to ask this question but I just need someone to explain why this is happening as I am battling to find any reference on this type of situation.
Thanks
SIZE, before using it.