C++ Quiz24 of 173
Difficulty:
⬅️ Prev: 29Quiz ID: 30Next: 31 ➡️

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

#include <iostream>
struct X {
  X() { std::cout << "X"; }
};

int main() { X x(); }
Hint

What is the difference between X x; and X x();?

Reveal answer

Explanation

This program has no output.

X x(); is a function prototype, not a variable definition. Remove the parentheses (or since C++11, replace them with {}), and the program will output X.

⬅️ Prev: 29Quiz ID: 30Next: 31 ➡️