@Sheenagoyal21
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’.