01/10/2018, 13:25
Tại sao dòng 'delete pa;' lại gây lỗi?
Ai giải thích giúp mình tại sao dòng [4] trong đoạn này lại gây lỗi với:
int A[5] = {10, 20, 30, 40, 50};
int *pa = A;
pa += 15;
delete pa;
Bài liên quan
delete
chỉ dùng vớinew
https://msdn.microsoft.com/en-us/library/h6227113.aspx
Using delete on a pointer to an object not allocated with new gives unpredictable results. You can, however, use delete on a pointer with the value 0. This provision means that, when new returns 0 on failure, deleting the result of a failed new operation is harmless. See The new and delete Operators for more information.
cám ơn @Trần Hoàn nhé