Question: What is wrong with this sequence of statements? int* p = new int[10]; p[10] = 5; delete[] p; The answer in my book is:The access

What is wrong with this sequence of statements?

int* p = new int[10];

p[10] = 5;

delete[] p;

The answer in my book is:The access p[10] is illegal; the returned array has elements with index 0 ... 9.

but i don't understand this explanation. Please explain why this is incorrect in detail.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!