If I declare an array in C/C++ like this int arr[5];
and then a loop to insert elements in it like this
for(int i=0; i<5; i++){
arr[i] = i+1;
}
And when I print those elements like this
for(int i=0; i<5; i++){
printf("%d ", arr[i]);
}
elements get printed as usual i.e 1 2 3 4 5
But if those loops are run one more time like this
for(int i=0; i<=5; i++){
arr[i] = i+1;
}
and this
for(int i=0; i<=5; i++){
printf("%d ", arr[i]);
}
then the output comes to be 1 2 3 4 5 6
.
So, I don't understand that how can an array of size 5 has 6 elements in itself?