You've answered 1 of 178 questions correctly. (Clear)

Question #193 Difficulty: 3

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

    #include <iostream>

int main() {
    int a[] = <%1%>;
    std::cout << a<:0:>;
}

Correct!

C++ provides alternative tokens for some punctuators. The two weird lines are exactly equivalent to

int a[] = {1};
std::cout << a[0];

§[lex.digraph]¶1 in the C++ standard explains this:

Alternative token representations are provided for some operators and punctuators.

§[lex.digraph]¶2:

In all respects of the language, each alternative token behaves the same, respectively, as its primary token, except for its spelling.

Then, a table of alternative tokens is provided, which includes
- <% and %> for { and }
- <: and :> for [ and ]

You can explore this question further on C++ Insights or Compiler Explorer!

Next question

Mode : Training

You are currently in training mode, answering random questions. Why not Start a new quiz? Then you can boast about your score, and invite your friends.

Contribute

Create your own!

Android app

Get Sergey Vasilchenko's CppQuiz Android app.

C++ Brain Teasers

Get the book, support the site! C++ Brain Teasers cover