Unsigned integer

"/* 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;
}"

please explain this question

hey @royprincejmp, conisider the following explnation

In case no other data type is specified such as in the statement
signed CodingBlocks = 9 ;
The compiler assumes it to be int by default.
This also works for long.
long int x = 9 ;
long x = 9 ;
Both these statements are equiavalant. Compiler takes int by default if no other data type is specified with the identifier.

As for signed char HackerBlocks = ‘A’ , as you know characters are stored as ASCII values in C++ ranging from 0 to 255.
If you were to declare a normal character and pass them to int variable , they would print the ASCII value.
char ch = ‘A’;
int y = ch ;
cout << y ; //Prints 65 - ASCII value of ‘A’

We can change it store the values not as 0 to 255 but as -127 to +127.
signed char ch = ‘A’
So if you were to simply print the character it would still print the character only.
cout << ch ; //Prints A

However , if you were to convert it to int now .
int x = ch ;
cout << x ;

The result of this is not defined and totally depends on the C++ standards defined by the compiler you are using.
It may print 65 only or it could print -62 ( -127 + 65 ).
While the conversion is guaranteed , its implementation could vary across compilers .
( It is guaranteed it would be either or the two , there won’t be a third answer. )

For the above problem , since we directly printing the variable HackerBlocks , we do not have to worry about this issue and the answer for this statement
cout<<HackerBlocks<<endl;
would simply be ‘A’.

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.