c - How can 256 be represented by a char? -
this question has answer here:
i ran following code in xcode in surprise answer 256. since char 8 bits long expected 0. dumping 1 in 8 place. can explain going on?
int main() { unsigned char = 0x80; printf("%d\n", i<<1); return 0; }
it being promoted integer, can contain value of 256 fine. cast unsigned char give result expected:
printf("%d\n", (unsigned char)(i<<1) );
Comments
Post a Comment