Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
unsigned short (synonymous with unsigned short int) is a fundamental integer data type in C that represents strictly non-negative whole numbers. By omitting the sign bit required in signed integers, it allocates all available memory bits to represent the magnitude of the value, effectively doubling the maximum representable positive limit compared to its signed counterpart.
Technical Specifications
- Memory Size: The C Standard (ISO/IEC 9899) guarantees that a
shortmust be at least 16 bits (2 bytes) in size. Its size must be less than or equal to the size of anint. - Value Range: to , where is the number of bits. On standard 16-bit implementations, the range is to .
- Standard Limits: The exact maximum value for the target architecture is defined by the
USHRT_MAXmacro, located in the<limits.h>header.
Syntax and Declaration
Theint keyword is implicit and can be omitted. Both declarations below are semantically identical:
Format Specifiers
When interfacing with standard I/O functions likeprintf and scanf, the unsigned short type requires the %hu format specifier (h for half/short, u for unsigned).
Integer Promotion
In C,unsigned short is subject to strict integer promotion rules. When an unsigned short is used as an operand in almost any arithmetic or bitwise expression (using operators like +, -, *, /, ~), it is implicitly promoted before the operation is evaluated. This promotion occurs regardless of the other operand’s type.
- If the standard
inttype can represent all possible values ofunsigned short(which is true on typical systems whereintis 32-bit andshortis 16-bit), theunsigned shortoperand is promoted to a signedint. - If
intandshortare the same size (e.g., both are 16-bit), the operand is promoted tounsigned int.
unsigned short variables together will promote both to int before the addition takes place, yielding an int result.
Arithmetic and Overflow Behavior
Becauseunsigned short operands are typically promoted to signed int during evaluation, arithmetic operations do not strictly operate using unsigned modulo arithmetic.
If the result of the promoted signed int arithmetic overflows INT_MAX, it results in Undefined Behavior (UB).
unsigned short variable.
Master C with Deep Grasping Methodology!Learn More





