Q:

C++ program...overshoots?

I'm decent at C++, but I may have missed some nuance that applies here.  Or maybe I completely missed a giant concept, I have no idea.  My program was instantly crashing ("blah.exe is not responding") about 1/5 times it was run (other times it ran completely fine) and I tracked the problem down to a constructor for a world class that was called once in the beginning of the main function.  Here is the code (in the constructor) that causes the problem:
int ii;
for(ii=0;ii<=255;ii++)
{
    cout<<"ent "<<ii<<endl;
    entity_list[ii]=NULL;
}
for(ii=0;ii<=255;ii++)
{
    cout<<"sec "<<ii<<endl;
    sector_list[ii]=NULL;
}
entity_list[0] = new Entity(0,0);
entity_list[0]->_world = this;

Specifically the second for loop.  The cout references are new for the sake of telling where it is having trouble.  It would print the entire "ent 1" to "ent 255" and then "sec 1" to "sec 255" and then crash right after, as if it was going for a 257th run through of the second for loop.  I set the second for loop to go until "ii<=254" which stopped all crashes.  Does C++ code tend to "overshoot" for loops or something?  What is causing it to crash at this specific loop seemingly at random?
By the way, entity_list and sector_list point to classes called Entity and Sector, respectively, but they are not constructing anything so I didn't think it would be relevant.  I also have a forward declaration for the Entity class in a header for this, but since none were being constructed I didn't think it was relevant either.

A:

You are going beyond the bounds of your array.
Based on your comment in Charles' answer, you stated:

I just declared them in the world class as entity_list[255] and
  sector_list[255]

And therein lies your problem. By declaring them to have 255 elements, that means you can only access elements a[0] through a[254] (If you count them up, you'll find that that is 255 elements. If index a[255] existed, then it would mean that there were 256 elements).

Now for the question: Why did it act so erratically when you accessed an element outside of the bounds of the array?
The reason is because accessing elements outside of the bounds of the array is undefined behavior in C++. I can't tell you what it should do, because it has been intentionally left undefined (don't ask me why--maybe someone who knows can comment?).
What this means is that the results will be sporadic and unpredictable, especially when you run it on different machines. 
It might work just fine. It might crash. It might delete your hard drive! (this one is unlikely, but doing so wouldn't be a violation of the C++ protocol!)
Bottom line--just because you got a strange or non-existant error message does NOT mean its ok. Just don't do it.

