πŸ“Š C Programming
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
πŸ’¬ Discuss
βœ… Correct Answer: (C) 56

Explanation: 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

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

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
272
Total Visits
πŸ“½οΈ
3 y ago
Published
πŸŽ–οΈ
Kanak Sharma
Publisher
πŸ“ˆ
88%
Success Rate