+ 2

what is myArr[0][2]=42; mean?

int[ ][ ] myArr = { {1, 2, 3}, {4}, {5, 6, 7} }; myArr[0][2] = 42; int x = myArr[1][0]; // 4

11th Jan 2018, 10:35 AM
zerosum
zerosum - avatar
3 odpowiedzi
+ 35
myArr [0][2] is 3 //its not 42 myArr [0][2]=42; //it means u r chaging its value from 3 to 42 myArr [0][2] mean go to 1st inside array & pickup 3rd element from it //hope it helps☺
11th Jan 2018, 10:46 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 15
You have 2-dimensional array and the second line is making the [0][2] element be equal to 42. MyArr before&after this action is { {1, 2, 3}, {4}, {5, 6, 7} };//before { {1, 2, 42}, {4}, {5, 6, 7} };//after Then you are printing the [1][0], which is 4
11th Jan 2018, 10:45 AM
Tato
Tato - avatar
0
1 2 3 4 5 6 7 This is the array in 2D. The changes is going to be in the ( first row ) && ( third column ) So it will be like this: 1 2 42 4 5 6 7
13th Jan 2018, 11:38 AM
Zam Al-mhdy
Zam Al-mhdy - avatar