K

Kanak Sharma • 5.38K Points
Tutor III

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

Explanation by: Kanak Sharma
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.


Question analytics