unsigned short vs unsigned int - sometimes they are the same range?

mpluse picture mpluse · Mar 17, 2013 · Viewed 97.2k times · Source

What's the difference between unsigned short and unsigned int? I found that unsigned short is 0-65,535 and unsigned int is 0-65,535 or 0-4,294,967,295. I don't understand the difference very well. How can I know the size of data type in my architecture? And if for example c = (unsigned short) d; when c is an unsigned short and d is an unsigned int ; what is that mean? the first 16 bits from d are assigned to c?

Answer

John Zwinck picture John Zwinck · Mar 17, 2013

You're really asking what is the difference between short and int. The answer is that short may be narrower, but may also be the same width as, int. That's virtually all we know for sure, independent of platform. A lot of platforms have 32-bit int and 16-bit short, but not all.