C++ Quiz166 of 173
Difficulty:
⬅️ Prev: 340Quiz ID: 342Next: 347 ➡️

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

#include <iostream>

int main()
{
    int i = 1;
    int& j;
    j = i;
    std::cout << j;
}
Hint

References must be immediately initialized.

Reveal answer

The program has a compilation error

Explanation

References must be immediately initialized. Not initializing j is a compilation error. §[dcl.init.ref]¶1:

A variable whose declared type is “reference to T” (§[dcl.ref]) shall be initialized.

⬅️ Prev: 340Quiz ID: 342Next: 347 ➡️