C++ Quiz107 of 173
Difficulty:
⬅️ Prev: 229Quiz ID: 230Next: 231 ➡️

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

#include <iostream>

struct X {
    int var1 : 3;
    int var2;
};

int main() {
    X x;
    std::cout << (&x.var1 < &x.var2);
}
Hint

How would the type of a pointer to a bit-field look like?

Reveal answer

The program has a compilation error

Explanation

int var1 : 3; declares a bit-field, and you can not apply operator& to a bit-field. §[class.bit]¶3 in the standard:

The address-of operator & shall not be applied to a bit-field, so there are no pointers to bit-fields.

⬅️ Prev: 229Quiz ID: 230Next: 231 ➡️