Why Do Arrays Have To Be Deleted via Delete[] in C++

This note is for C++ beginner programmers who are wondering why everyone keeps telling them to use delete[] for arrays. But, instead of a clear explanation, senior developers just keep hiding behind the magical "undefined behaviour" term. A tiny bit of code, a few pictures and a glimpse into the nuts and bolts of the compilers – if interested, you're welcome to read.

Introduction

You may not have noticed, or even just not paid attention, but when you write code to release the memory space occupied by arrays, you don't have to enter the number of items to be deleted. And it all works great, though.

CategoriesUncategorized