Why does this code work?
It has access to p[1 and 2] even though I never declaredCode:#include <iostream>
using namespace std;
int main()
{
int * p;
p = new int;
p[0] = 3;
p[1] = 7;
p[2] = 4;
cout << p[0] << endl;
cout << p[1] << endl;
cout << p[2] << endl;
return 0;
}
If it's valid code, whats the point of declaring how many new you want?Code:p = new int [3];