+ 2

Why does this code work?

One of the challenges in c++ describes that the output of std::cout << 1["abc"] << endl; is 'b', or if you replace the '1' with a '2' the output is 'c' --> so the number indicates the index in the 'array' ["abc"]. But I am not aware that you can declare an array with ["abc"] and access the elements by prepending the index. So what code will the compiler generate?

2nd Jan 2019, 8:59 PM
nobody
3 Answers
2nd Jan 2019, 10:35 PM
nobody
+ 1
Anna now you rewrote it, first and third line are regular c++ using the subscript operator to access elements of a regular c++-array. But why does the second line work, this really surprises me.
2nd Jan 2019, 9:27 PM
nobody