C++ Quiz31 of 173
Difficulty:
⬅️ Prev: 38Quiz ID: 41Next: 42 ➡️

According to the C++23 standard, what is the output of this program?

#include <iostream>
int main() {
  std::cout << 1["ABC"];
}
Hint

The expression E1[E2] is identical to *((E1)+(E2)).

Reveal answer

B

Explanation

§[expr.sub]¶2 in the standard:

The expression E1[E2] is identical (by definition) to *((E1)+(E2)) (...).

In our case 1["ABC"] is identical to *(1+"ABC"). Since the plus operator is commutative, this is identical to *("ABC"+1), which is identical to the more familiar "ABC"[1].

⬅️ Prev: 38Quiz ID: 41Next: 42 ➡️