`unsigned` — C++ Keyword
`unsigned` — C++ Keyword
The unsigned keyword in C++: marks an integer type as unsigned (non-negative only).
`unsigned` — C++ Keyword
The unsigned keyword in C++: marks an integer type as unsigned (non-negative only).
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
unsignedMarks an integer type as unsigned, meaning it holds only non-negative values but has twice the positive range of the corresponding signed type. Unsigned arithmetic wraps modulo $2^N$.
unsigned char uc;
unsigned short us;
unsigned int ui; // 'int' optional: unsigned == unsigned int
unsigned long ul;
unsigned long long ull;
#include <print>
#include <climits>
int main() {
unsigned int u = 4'294'967'295u; // UINT_MAX on 32-bit int
std::println("{}", u); // 4294967295
// Unsigned wrap-around is well-defined
unsigned char uc = 255;
++uc;
std::println("{}", uc); // 0 (wraps)
// Comparing signed and unsigned – common pitfall
int n = -1;
// if (n < u) ... // n is converted to unsigned, becomes UINT_MAX
}
std::size_t (which is unsigned) for sizes and indices that interface with the standard library.int main() {
// Pick one facility from this reference page.
// Write the smallest program that exercises its main precondition,
// complexity rule, or lifetime constraint before scaling up.
return 0;
}