+ 1
Output of this code is 8? How
include <iostream> using namespace std; int main() { int arr[] = {1,2,3,4,5,6}; { cout<<arr[6]; } return 0; }
3 Answers
+ 2
thats undefined behavior. When array goes out of bounds, it finds unused memory and prints it out. Your array index begins at 0 and ends at 5.
+ 2
The array name is a pointer to the first value it holds. So when you go beyond the memory range of the array, youâre accessing a value you never put in. You may get a larger number if you put in something like 7, and thats probably an address to something else in memory
+ 1
Thank you both of you