two array's in Struct

I'm preparing for C++ institute exam. One of the questions is below. The outcome is 34 but I can't figure out why. I don't know how to approach this. Any body any idea how to solve this without a compiler (reason it out)?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
     #include <iostream>
    using namespace std;
    
    struct sct {
        int t[2];
    };
    
    struct str {
        sct t[2];
    };
    
    int main() {
            str t[2] = { {0, 2, 4, 6}, {1, 3, 5, 7} };
            cout << t[1].t[0].t[1] << t[0].t[1].t[0];
            return 0;
    }
The topic is aggregate initialization.
http://en.cppreference.com/w/cpp/language/aggregate_initialization

str is an aggregate object containing an array of 2 sct.
sct is an aggregate object containing an array of 2 int.

Each braced list of 4 ints on line 13 initializes one str (although those braces could be omitted too.) Aggregate initialization causes each sub-object to be initialized recursively in the order of appearance (follow the link.)

As my debugger displays, the layout of t (the one declared in the main function) is:
 
$1 = {{t = {{t = {0, 2}}, {t = {4, 6}}}}, {t = {{t = {1, 3}}, {t = {5, 7}}}}}
Last edited on
Topic archived. No new replies allowed.