C Programming :: Declarations and Initializations - Discussion
48 / 54
#include<stdio.h>
int main()
{
char c = 255;
printf ("%d",c);
return 0;
}
#include<stdio.h>
int main()
{
char c = 255;
printf ("%d",c);
return 0;
}
Aillegal character assignment
Bprints -1
Cprints 2
Dprints 255
Show Explanation
Before that, we should know that char can store numbers only -128 to 127. The most significant bit is kept for the sign bit. Clearly, 11111111 represents a negative number. To check which number it represents we find the 2’s complement of it, which is 00000001, which is nothing but 1 in decimal.
Hence, 11111111 represents -1, which is the required output.
Asked In ::
255 in binary can be represented as 11111111. What does this number represent?
Before that, we should know that char can store numbers only -128 to 127. The most significant bit is kept for the sign bit. Clearly, 11111111 represents a negative number. To check which number it represents we find the 2’s complement of it, which is 00000001, which is nothing but 1 in decimal.
Hence, 11111111 represents -1, which is the required output.
Read Full Answer
Report Error
Please Login First Click Here