In the code:
#include <bits/stdc++.h>
using namespace std;
int main() {
int *arr = new int[15];
for (int i = 0; i < 5; i++)
arr[i] = 2 * i;
for (int i = 0; i < 5; i++)
cout << arr[i] << " ";
cout << endl;
delete[] arr;
for (int i = 0; i < 5; i++)
arr[i] = 3 * i + 1;
for (int i = 0; i < 5; i++)
cout << arr[i] << " ";
cout << endl;
return 0;
}
Output:
0 2 4 6 8
1 4 7 10 13
i.e. there is no error
How are we able to access and modify an array which does not exist in the memory?