+ 1

Explain how this works→

#include <iostream> using namespace std; int main() { int arr3[2][3][3]={ { {5,6,2},{3,4,4},{2,7,5}}, { {5,7,6},{7,8,1},{1,2,6}} }; int i=0,j; for(j=0;j<2;j++){ i += arr3[j][j][j]; }cout << i; return 0; } why 'i' value is 13? ........i know!!

10th Dec 2017, 8:18 PM
Mind To Machine đŸ’»đŸ•†
Mind To Machine đŸ’»đŸ•† - avatar
4 Answers
+ 11
arr3[0][0][0] and arr3[1][1][1] was added to i, i is printed. (5 + 8) = 13.
11th Dec 2017, 1:25 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
#include <iostream> using namespace std; int main() { int arr3[2][3][3]={ { {5,6,2},{3,4,4},{2,7,5}}, { {5,7,6},{7,8,1},{1,2,6}} }; int i=0,j; for(j=0;j<2;j++){ i += arr3[j][j][j]; cout << "arr3[" << j << "][" << j << "][" << j << "]=" << arr3[j][j][j] << endl; }cout << "summa ="<< i; return 0; } //why you get 13 as the answer?
10th Dec 2017, 8:51 PM
Konstantin
+ 1
@Konstantin i think you meant "sum" not "summa"
10th Dec 2017, 9:00 PM
Mind To Machine đŸ’»đŸ•†
Mind To Machine đŸ’»đŸ•† - avatar
+ 1
Yes. )
10th Dec 2017, 9:03 PM
Konstantin