When you typecast from an int to a char, you are cutting down the number of bytes used from 4 to 1. How does it pick which byte it is going to use make the char?
Does it take the most significant byte?
Or does it take the least significant?
Or is there some sort of rule I should know about?
C will take the least-significant byte when doing a narrowing conversion, so if you have the integer value 0xCAFEBABE and you convert it to a char, you’ll get the value 0xBE.
Of course, there’s no actual guarantee that an
intis four bytes or that acharis one, but I’m pretty sure that the logic for doing the truncation will always be the same and will just drop the higher-order bits that don’t fit into thechar.