char cc = 255;
if(cc == 255)
{
  printf("cc equal to 255");
}
else
{
  printf("cc not equal 255");
}
Answer: cc not equal 255

The line cc = 255 will give a warning but not an error in C. After execution of this statement, value of cc will be -1. Char variable takes 7 lower bits as magnitude and the most significant bit as signature. In this case, all bits including the signature bit is 1 which makes it a negative number. The value of the negative number may be calculated as shown below:

Value of 
cc = Negative signature( two's complement of binary 1111111)
   = Negative( not of binary 1111111 + 1)
   = Negative( 0 + 1)
   =-1

About our authors: Team EQA

You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.

Learn on Youtube

#