C++ Quiz51 of 173
Difficulty:
⬅️ Prev: 121Quiz ID: 122Next: 124 ➡️

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

#include <iostream>

typedef long long ll;

void foo(unsigned ll) {
    std::cout << "1";
}

void foo(unsigned long long) {
    std::cout << "2";
}

int main() {
    foo(2ull);
}
Hint

What does unsigned imply by default?

Reveal answer

2

Explanation

§[dcl.spec.general]¶3 states:

If a type-name is encountered while parsing a decl-specifier-seq, it is interpreted as part of the decl-specifier-seq if and only if there is no previous defining-type-specifier other than a cv-qualifier in the decl-specifier-seq.

§[dcl.spec.general]¶note-1 mentions our case specifically:

Since signed, unsigned, long, and short by default imply int, a type-name appearing after one of those specifiers is treated as the name being (re)declared.

In void foo(unsigned ll), since unsigned implies int, ll is being redeclared as a parameter name.

⬅️ Prev: 121Quiz ID: 122Next: 124 ➡️