what is wrong with the add_to_array function that would cause this behaviour?

You say that your program is supposed to crash. Therefore, the root of the problem is not the add_to_array function: it is with what you want.

The add_to_array function looks wrong, certainly. It is a misnomer, and then it does not do even what it claims to do in its output, i.e., despite bring named add_to_array, it does not add to any array, and despite printing text with "array size" and "object size" labels, it does not actually print any array size or object size (other than pointer sizes). But these are wrong in a different way from what you are asking.

Originally Posted by Bjarne Stroustrup (2000-10-14)

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

yes, originally I wanted to write a function that added an object to the first empty space in the array, or if the array was full...create a new larger array and copy the objects to the new larger array (and dispose of the old one)

so then , just to make sure I understood the language I decided to reduce the array size to 1 and then it didnt crash so I got worried.

What Im worried about is 'the future' what If I make a mistake and I am not warned...instead the program will do 'undefined behaviour' and I wont have a clue what is going wrong.

It would help me to know what is causing the error in the (badly named) function