   no array out of bounds error
  Hi.  Why do I not get an error that the array is out of bounds in the following code? (C++)#include <iostream>using namespace std;int arr[128];int main(){    for(int i = 0 ; i <160 ;i++){arr = i;  cout << arr << endl;}   system("PAUSE");return 0;}
  int arr[128];for(int i = 0 ; i <160 ;i++)   ;  C++ doesn't do array bound checking, normally.  It's a performance thing.  No reason to do it unless the program specifically wants it.  And then, as far as I know, it is only available if you manually check it yourself, or if you use standard containers, like std::vector, and use functions like .at() that include bounds checking.   ;  C++, unlike languages like Java or C#, can be considered to be an unsafe language. C++ will happily allow you to read past (or even before) the bounds of your arrays, create pointers into random memory addresses and otherwise trusts the programmer with as much power as the operating system will give an application.   ;  There is no array out of bounds error in C++   ;Quote:Original post by Frunyint arr[128];for(int i = 0 ; i <160 ;i++)He was asking why he was not getting an overflow error.The answer is probaly that you are not overwriting anything essential. What compiler are you using?   ;  Ah thanks. I thought that was a bit strange. Does that mean it's actually unsafe to do that, or is it just bad practise? Also, reading from C++ for Dummies, it says "valueArray[128] can store up to 128 integers. Since arrays start from zero, shouldn't valueArray[128] be able to store up to 129 integers?Thanks   ;Quote:Original post by phiAh thanks. I thought that was a bit strange. Does that mean it's actually unsafe to do that, or is it just bad practise? Also, reading from C++ for Dummies, it says "valueArray[128] can store up to 128 integers. Since arrays start from zero, shouldn't valueArray[128] be able to store up to 129 integers?ThanksvalueArray[128] can only be indexed 0-127, otherwise you would be right   ;Quote:Does that mean it's actually unsafe to do that, or is it just bad practise?Both. The behavior resulting from an out-of-bounds access is undefined (often you get an access violation at run time, though).   ;Quote:Original post by phiAh thanks. I thought that was a bit strange. Does that mean it's actually unsafe to do that, or is it just bad practise? Also, reading from C++ for Dummies, it says "valueArray[128] can store up to 128 integers. Since arrays start from zero, shouldn't valueArray[128] be able to store up to 129 integers?ThanksIt's unsafe to do that, and you shouldn't. C++ doesn't do any checking for you at compile-time or run-time, so you have to be careful.valueArray[128] will store 128 elements, from indices 0 to 127.   