unsigned Unsigned integer specifier
unsigned Unsigned integer specifier
unsigned means unsigned int for nonnegative values. It wraps modulo 2^N for N value bits, so UINT_MAX + 1u is 0; mixed signed arithmetic needs care.
| Category | Type specifiers |
|---|---|
| Kind | Keyword / Statement |
| C standard | C89 / C90 |
📝 Syntax
unsigned int u = 4000000000u;
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
wrap to zero = 0
wrap to UINT_MAX = 1
🏷️ Related type specifiers
📚 Related Tutorials
❓ FAQ
QDoes 0u - 1u produce a negative value in unsigned int?
ANo. Unsigned arithmetic is modulo 2^N, so the result wraps to UINT_MAX. This behavior is defined by the standard, unlike signed negative overflow, which is undefined.
QWhy can -1 < 1u evaluate to false?
AIn a common operation between int and unsigned int of equal rank, int is converted to unsigned int. Thus -1 becomes a very large unsigned value. Choose appropriate types and ranges before mixed comparisons.
QWhere can the value of UINT_MAX be found?
AInclude limits.h and use the UINT_MAX macro, which gives the maximum value of unsigned int. Do not hard-code 4294967295 in portable code because unsigned int is not guaranteed to be 32 bits.