0

Why are we incrementing a variable k in a two dimensional array l

like int a[][]=new int[4][5]; int i,j, k=0; for(i =0;i <4; i++) for(j=0;j<5;j++){ a [i ][j]=k; k++;}

19th Aug 2018, 5:12 PM
Shivyaaa
4 Respostas
+ 2
All array values are 0. After that k becomes 1. k++ is outside of both loops.
19th Aug 2018, 5:49 PM
Микола Федосєєв
Микола Федосєєв - avatar
+ 1
Now I see brackets, which combine array value asignment and incrementing of k. That fills array as {{0,1,2,3,4},{5,6,7,8,9} ... etc
19th Aug 2018, 6:49 PM
Микола Федосєєв
Микола Федосєєв - avatar
+ 1
"we are storing value of a[I][j] in k" - oh, no. We are storing the value of k in a[i][j].
19th Aug 2018, 7:47 PM
Микола Федосєєв
Микола Федосєєв - avatar
0
we are storing value of a[I][j] in k but why are we incrementing k
19th Aug 2018, 5:53 PM
Shivyaaa