Quiz 1 fundamental question 5

"/* Output ? */
#include
using namespace std;

int main(){
long signed CodingBlocks = 2017;
short unsigned BOSS1 = -2018;
unsigned BOSS2 = -2019;
int BOSS3 = -2020;
long long unsigned BOSS4 = -2021;
short unsigned Nagarro = 2018.9;
long signed HackerBlocks = ‘A’;
cout<<CodingBlocks<<endl;
cout<<BOSS1<<endl<<BOSS2<<endl<<BOSS3<<endl<<BOSS4<<endl;
cout<<Nagarro<<endl;
cout<<HackerBlocks<<endl;

return 0;
}"

2017 2^16 - 2018 2^32 -2019 -2020 2^64 - 2021 2018 65

2017 2^16 - 2018 2^32 -2019 -2020 2^64 - 2021 2018 65
2017 2018 2019 2020 2021 2018.9 A

2017 2018 2019 2020 2021 2018.9 A
2017 2^32 - 2018 2^32 -2019 -2020 2^32 - 2021 2018 65

2017 2^32 - 2018 2^32 -2019 -2020 2^32 - 2021 2018 65
2017 2^32 - 2018 2^32 -2019 -2020 2^64 - 2021 2018 64

2017 2^32 - 2018 2^32 -2019 -2020 2^64 - 2021 2018 64
can you explain to me how 3rd answer is right?

Hello,

Let’s understand this with an example.
Suppose you assign -2 to an unsigned integer
then for 32 bits int it will results in 2^32 - 2
And it would be 2^16 - 2 for short unsigned integer
And similarly, for long long unsigned integer it would be 2^64 - 2

Hope, this would help.
Give a like if you are satisfied.

sir but we can only assign the positive values for unsigned and here we storing -2018…how it is correct?

What i have told above is basically unsigned representation of negative numbers short different unsigned data type.
Yes, as an unsigned type cannot store the negative sign, thus the compiler converts it into an above mentioned unsigned representation.

Hope, i have cleared your doubts.