+ 2

When i type this code (code is in description) i get answer 4232000 I want to know how i got it?

#include <iostream> using namespace std; int main() { int x[2][3] = {{2, 3, 4}, {8, 9, 10}}; cout << x[2][0] << endl; return 0; }

18th Apr 2017, 8:33 AM
Harikrishnan s
Harikrishnan s - avatar
5 Answers
+ 9
You're accessing memory out of the array range, so you get a "random" memory value.
18th Apr 2017, 8:36 AM
Karl T.
Karl T. - avatar
+ 9
an array starts from 0 not 1 remember
18th Apr 2017, 9:13 AM
Umbe
Umbe - avatar
+ 4
Out of array they will return that value
18th Apr 2017, 8:36 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 3
Possible outcomes: x[0][0] = 2 x[0][1] = 3 x[0][2] = 4 x[1][0] = 8 x[1][1] = 9 x[1][2] = 10 x[2][0] is out of range On VC++ you'll get a debug error instead of a random garbage.
18th Apr 2017, 9:05 AM
Babak
Babak - avatar
- 1
I think that this is fun! â˜șâ˜ș😁â˜ș😁😁
27th Apr 2017, 4:12 AM
WebTop Three
WebTop Three - avatar