C++ Quiz29 of 173
Difficulty:
⬅️ Prev: 35Quiz ID: 37Next: 38 ➡️

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

#include <iostream>

int main() {
  int a = 0;
  decltype(a) b = a;
  b++;
  std::cout << a << b;
}
Hint

What type is decltype(a)?

Reveal answer

01

Explanation

According to §[dcl.type.decltype]¶1.3 in the standard:

For an expression E, the type denoted by decltype(E) is defined as follows:

— (...)

— otherwise, if E is an unparenthesized id-expression (...), decltype(E) is the type of the entity named by E.

The type of a is int, so the type of b is also int.

⬅️ Prev: 35Quiz ID: 37Next: 38 ➡️