Program wont run correctly
I keep getting an error and then breaks my program but have no idea why. Can someone help me with this please?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
#include <iomanip>
using namespace std;
int* reverseArray(int*, int);
int main()
{
const int size = 5;
int arr[size] = {1,2,3,4,5};
int* rev=arr;
for(int i=0; i<size; i++)
{
cout <<arr[i];
}
delete[] rev;
rev=NULL;
system("PAUSE");
return 0;
}
|
Only delete[] things that you created with new[].
You did not allocate 'rev' with new[]. Therefore you must not delete[] it.
In fact... 'rev' is completely useless in this code and you can remove it completely.
This is correct:
1 2 3 4 5 6 7 8 9 10
|
int main()
{
const int size = 5;
int arr[size] = {1,2,3,4,5};
for(int i=0; i<size; i++)
{
cout <<arr[i];
}
}
|
Topic archived. No new replies allowed.