C++ Quiz141 of 173
Difficulty:
⬅️ Prev: 289Quiz ID: 291Next: 293 ➡️

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

#include <iostream>

int _global = 1;

int main() {
  std::cout << _global;
}
Hint

The answer would be different if the variable was named just global.

Reveal answer

The program is (or may be) undefined

Explanation

The standard defines some identifiers as reserved to the implementation.

§[lex.name]¶3:

In addition, some identifiers appearing as a token or preprocessing-token are reserved for use by C++ implementations and shall not be used otherwise; no diagnostic is required.

— Each identifier that contains a double underscore __ or begins with an underscore followed by an uppercase letter is reserved to the implementation for any use.

— Each identifier that begins with an underscore is reserved to the implementation for use as a name in the global namespace.

⬅️ Prev: 289Quiz ID: 291Next: 293 ➡️