A

Admin • 833K Points
Coach

Q. What will be the output of the following C code?

Code:
#include <stdio.h>

int main()
{
unsigned char c=290;
printf("%d",c);
return 0;
}
  • (A) 290
  • (B) 234
  • (C) 56
  • (D) Garbage
  • Correct Answer - Option(C)
  • Views: 26
  • Filed under category C Programming
  • Hashtags:

Explanation by: Admin

290 is beyond the range of unsigned char. Its corresponding value printed is: (290 % (UCHAR_MAX +1) where UCHAR_MAX represents highest (maximum) value of unsigned char type of variable. The value of UCHAR_MAX=255. Thus it prints 290 % (UCHAR_MAX+1)=34

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.