- 2

#include <stdio.h> int main() { int x[5] = {20, 45, 16, 18, 22}; printf("The element is %d\n", x[5]); /* 32766 */

Can someone tell me how the index value of 5 in coming as 32766...

23rd Jan 2022, 4:35 AM
Diya Mehta
Diya Mehta - avatar
3 Answers
+ 4
Er, how do you know x[6] is expected to be zero? Again, it is outside the boundary of the array. You must presume the value is unpredictable. (Though, in some cases it IS predictable if you understand memory organization).
23rd Jan 2022, 5:07 AM
Brian
Brian - avatar
+ 1
Understand that x[5] is indexing outside the bounds of the array. You are seeing what is next in memory past the end of the array.
23rd Jan 2022, 5:00 AM
Brian
Brian - avatar
+ 1
Ohky thanks 😊
23rd Jan 2022, 5:10 AM
Diya Mehta
Diya Mehta - avatar