From C standard, int has of at least 16bit, long has of at least 32bit and at least 64bit for long long if any (some platforms may not support). Just wondering if the sentence as title is always true.
No. The standard only defines the minimum ranges for each of those types. Conceivably int could have a 16-bit range, but 48 bits of padding, bringing it to 64-bits (8 bytes, if CHAR_BITS == 8), while long is 32-bits (4 bytes).
Of course, this would be silly. But it's not forbidden, as such.
Note, however, that sizeof(char) == 1
, by definition. So sizeof(char) <= sizeof(
anything else)
.
According to C Programming/Reference Tables, particularly the Table of Data Types:
int ≥ 16 ≥ size of short
long ≥ 32 ≥ size of int
long long ≥ 64 ≥ size of long
As bdonlan pointed out, this only refers to the range of the values, not the size in memory (which sizeof returns in bytes). The C standard doesn't specify the size in memory that each type can use, so it's left to the implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With