Which of the following variable declarations compile and what would be the value of a?
unsigned int a1 = 42;
unsigned int a2{42};
unsigned int a3 = -42;
unsigned int a4{-42};Show answer and explanation
Declarations 1, 2, and 3 compile. The first two produce 42; assigning -42 converts modulo one more than the maximum unsigned value, while braced initialization in declaration 4 rejects that non-constant narrowing conversion.
Declarations 1, 2, and 3 compile. The first two produce 42; assigning -42 converts modulo one more than the maximum unsigned value, while braced initialization in declaration 4 rejects that non-constant narrowing conversion.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.