+ 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?
3 Answers
+ 1
Ok, I found the explanation on stackoverflow: https://stackoverflow.com/questions/381542/with-arrays-why-is-it-the-case-that-a5-5a
+ 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.