What does the postfix (or suffix) U
mean for the following values?
0U 100U
It means that it is an unsigned hexadecimal constant of value 47 hex = 71 decimal. If the 'u' is omitted then it is a signed hexadecimal constant of value 47 hex.
1U is unsigned. It can carry values twice as big, but without negative values. Depending on the environment, when using U, i can be a maximum of either 31 or 15, without causing an overflow. Without using U, i can be a maximum of 30 or 14. 31, 30 are for 32 bit int.
it means "unsigned int", basically it functions like a cast to make sure that numeric constants are converted to the appropriate type at compile-time.
Thus ~0u means the maximum value of an object of type unsigned int when each bit of its internal representation is set to 1.
It stands for unsigned
.
When you declare a constant, you can also specify its type. Another common example is L
, which stands for long
. (and you have to put it twice to specify a 64-bit constant).
Example: 1ULL
.
It helps in avoiding explicit casts.
Integer constants in C and C++ can optionally have several suffixes:
123u the value 123 is an unsigned int
123l (that's a lowercase L) 123 is a signed long
123L ditto
123uL unsigned long
123LL a signed long long, a 64 bit or 128 bit value (depending on the environment)
123uLL unsigned long long
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