+ 3
Unexpected Output of array in c++
in this statement the is expected to be 0 but it's 8!(like my code named "arr").why? int b[6] = {12, 35, 212, 17, 9}; cout<< b[6] << endl;
4 odpowiedzi
+ 6
The memory you are trying to access is out of the bounds of the array. You haven't assigned a value to it, so you get whatever was stored in that memory cell before, which is not necessarily 0.
+ 4
Mohsen you have defined an array b of size 6 and are trying to access the 7th element which does not exist. Remember that array indexes start from 0. The value of 8 that you get may be from a random area of memory. This type of out of bounds access can also generate an error.
+ 3
array indexes starts from 0 , and you are not storing anything at 6th position , that's why