0

[SOLVED] Why int arr[5]; is working for arr[5]?

Shouldn't it work only upto arr[4]? Ie. arr[0] arr[1] arr[2] arr[3] arr[4]. Checkout this program https://code.sololearn.com/cZ4G78yVH74E/?ref=app Why this is working so well? Without any errors. The program executes even for arr[6] arr[7] etc without any compile time errors although it gives wrong output. But it works perfectly fine for arr[5]. Why?

26th Aug 2021, 8:04 AM
Yugal Kishore
2 Réponses
+ 1
Unlike Java or other "safe" language, C++ does not prevent you (the coder) from doing out of bounds array iteration or modification (occasionally). https://www.tutorialspoint.com/Why-accessing-an-array-out-of-bounds-does-not-give-any-error-in-Cplusplus http://www.cplusplus.com/forum/beginner/248886/
26th Aug 2021, 8:19 AM
Ipang
+ 1
Thanks for your answer
26th Aug 2021, 8:30 AM
Yugal Kishore