In C when one data type is cast to a different data type (for example an int
to a short
) the extra bits are simply truncated. This results in a loss of information starting with the leftmost bits.
This can cause strange effects to negative numbers in particular due to the Two's Complement representation of negative integers. This is because a truncation will cut off the Most Significant Bit which is used to denote special information about sign.
However, if the number is within the range of both datatypes no data loss will occur and you end up with the same value represented in both cases.