Data Structures: Arrays
Source: Data Structures for Game Programmers by Ron Penton
An array is called a linear data structure. When you represent arrays in figures you can use squares to represent the cells and the first cell has an index of 0. But that doesn’t always have to be the case.
Static Array: An array is called static when its size cannot be modified. These are the easiest types of arrays to create and manipulate.
When you create an array in C/C++, the array is not initialized. So what happens is that the array holds junk, and you have no idea what is in the array right after you create it.
When an array is accessed past the end one of several things will happen. If you are just reading memory, there might not be a problem. Your program might crash tho because your compiler has code that detects if you are reading memory out of bounds and the code throws an error. It can also read a value that was total junk and not crash at all. Your program reads a junk value, and for all intents and purposes, it thinks the value is valid. Stuff like that can be very difficult and time consuming to track down.
When C/C++ creates an array, it does two things: It makes enough room for the array in memory, and it treats the name of the array as a pointer to the block of memory where the array is stored.
The name of the array is a pointer to the memory location of the first element.