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.

CategoryType specifiers
KindKeyword / Statement
C standardC89 / 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 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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏