0
Unsigned char
unsigned char x=300; printf("%d", x) ; // why output is 44?
2 Respuestas
+ 5
Unsigned char is used, with a range 0-255, or in other words, the maximum number in 1 byte, or 8 bits of memory (as 2**8 =256). Since 300 has been assigned, the number overflows, and starts at 0, and since 300-255=45, starting from 0, that means that the variable overflows to 44. Hence printed it will output 44
+ 2
When an unsigned char value assignment overflows, you can calculate it as <value> % 256.
Here you assigned value 300 to an unsigned char variable. But that value is out of unsigned char data range (0 ~ 255), and thus you got 44, because 300 % 256 results in 44.