Output of a program

#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;
}

can someone explain me the output of this program?

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’;

three rules are used here:

  1. if character is stored in numeric type variable, its ASCII will get printed.
    cout<<HackerBlocks; //ASCII of A = 65

  2. if decimal is stored in integral type, its fractional part will be lost.
    cout<<Nagarro; // 2018.9 will be converted to 2018

  3. unsigned type means only positive value, so when we store -ve value in an unsigned type, it convert it to +ve value by rotation.
    how rotation happens?
    lets say unsigned short x= -23;
    unsigned short is of size 2 bytes. with range [0, 65535]. think this array as circular array,
    then -1 = 65535, -2 = 65534,…-23 = 65535-(23-1) = 65513
    eg.
    a. short unsigned BOSS1 = -2018; // BOSS1 = 65535-(2018-1) = 63518

b. unsigned BOSS2 = -2019;
// default is int. so it is unsigned int with range [0,4294967295] as int size is 32 bit so 0 to (2^32)-1.
cout<<BOSS2; // 4294967295-2018 = 4294965277

so on…
thanks
please rate and resolve if satisfied.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.