Wierd Array Behavior

I have been working with c++ for a little bit and have just noticed some interesting behavior with arrays.

I have put my code on pastebin since it is starting to get rather lengthy.
http://www.pastebin.org/238633

I have multiple arrays defined globally but the behavior i have noticed only applies to 2 of them. hand and foot. the first dimension ([4]) represents the number of players.

while running what i have of the program so far to test to make sure that every thing is working properly i accidentally input "number of players" as 5. As soon as i hit enter and realized what i had done i was expecting the program to have a heart attack and shit the bed on me. However the program actually added a 5th row to both my hand and foot arrays.

My question is is this just dumb luck that it worked or what.
Also on the off chance that it is not just dumb luck could i define the arrays
1
2
hand [][]
foot [][]

and have them autoadjust to the lengths needed for each dimension.

I have a feeling that this is just a fluke and that i shouldn't be able to enter a player number higher than 4 and have it work.

Any input on this "issue" would be greatly appreciated

Arrays aren't resized when overflowed. Or ever, for that matter.
The stack is where all variables and function calls are stored and its size is fixed. What this means is that writing past the end of a stack array (known as a buffer overflow, a kind of memory bug) doesn't necessarily crash the program, but there's no telling what was stored where you wrote. Maybe there was nothing, maybe there was critical data, but whatever it was is now gone.

For now, accept this fact: arrays can't be resized.
Later on you'll see how you can write code that makes arrays behave as though they grow. They don't actually grow, but the effect is ultimately the same
Thank you helios. I figured it was something along those lines but i wasn't sure.
Topic archived. No new replies allowed.