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;
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;
delete chỉ dùng với new
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é
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?