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:
-
if character is stored in numeric type variable, its ASCII will get printed.
cout<<HackerBlocks; //ASCII of A = 65
-
if decimal is stored in integral type, its fractional part will be lost.
cout<<Nagarro; // 2018.9 will be converted to 2018
-
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.