+ 4
Why this code prints 44 ?
#include <stdio.h> int main() { unsigned char x = 300; printf ("%d", x); return 0; }
3 Respostas
+ 18
unsigned char is between [0, 255]
300 is bigger than 255 so it throws away extra bits and you get 300 % 256 = 44
+ 6
unsigned char are 1 byte (8 bits) long...
But to represent 300 9 bits are needed, so there is no room in x for the 9th bit
If you use binary or hexa:
300 is: 1 0010 1100 12C
When assigned to unsigned char bit 8 (9th bit) is discarded, so:
x = 0010 1100 2C
2*16 + 12 = 44
:)
+ 2
good answer diego Code