C++ Quiz45 of 173
Difficulty:
⬅️ Prev: 114Quiz ID: 115Next: 116 ➡️

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

#include <iostream>

void f(int) { std::cout << "i"; }
void f(double) { std::cout << "d"; }
void f(float) { std::cout << "f"; }

int main() {
  f(1.0);
}
Hint

What's the type of a floating point literal?

Reveal answer

d

Explanation

According to §[lex.fcon]¶1 in the standard:

The type of a floating-point-literal (§[basic.fundamental], §[basic.extended.fp]) is determined by its floating-point-suffix as specified in Table 11.

And Table 11 maps floating-point-suffix "none" to "double".

The best overload is therefore void f(double).

⬅️ Prev: 114Quiz ID: 115Next: 116 ➡️