I am having an issue with outputting an array. When I output each element without a for loop, the program runs fine. When I try to output with a for loop, the program crashes the first time I set an element in the array. I have marked the line where the program crashes when I uncomment out the for loop. My sort seems to work fine and the program is crashing way before that, so I'm pretty sure that isn't the issue. Any ideas why the 2nd for loop would crash the program at the specified line?
int main()
{
int* Array;
int j = 5;
for(int i=0; i<5; i++)
{
Array[i] = j; //Crashes here with 2nd for loop uncommented
cout << Array[i] << endl;
j--;
}
Array = insertion_sort(Array);
cout << Array[0] << endl;
cout << Array[1] << endl;
cout << Array[2] << endl;
cout << Array[3] << endl;
cout << Array[4] << endl;
/*for(int k=0; k <5; k++)
{
cout << Array[k] << endl;
}*/
}
Array = insertion_sort(Array);will fail to compile ifArrayreally was an array.