Let's say you are writing a piece of code, and it is very important that the code behaves nicely for all input. An "assertion" is a way of making sure that your inputs are what you expect, and that your code is on the right track.
For example, let's say you are writing a divide function that takes two integers, "numerator" and "denominator", and returns the quotient. If denominator is zero, then what will your function return? The input doesn't really make sense in this context. In this case, you may be tempted to put an assertion at the start of your code. e.g.
ASSERT(denominator != 0)
When the program is running, it will throw an assertion error if someone passes a denominator of zero into your divide function. Typically assertions are only processed in debug mode so that you can identify and fix serious errors in your program before you compile an optimized release version.
So, in this case, the standard C runtime memory manager has an assertion in its delete function. i.e. the array delete function asserts that the parameter is, in fact, an array.
If you had run in release mode, it probably would have just crashed on that line, or corrupted memory.
|