First of all, the size of int/long is unspecified. So on your compiler, an int
and a long
might be the same, but this isn't universal across compilers.
As for the difference between unsigned long
and long
:
Assuming 4 bytes, a long
has the range of -2,147,483,648
to 2,147,483,647
. An unsigned long has the range of 0
to 4,294,967,295
.
One other difference is with overflow. For a signed type, an overflow has unspecified behavior. But for an unsigned type, overflow is guaranteed to "wrap around."
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…