Abstract

The unsigned short int type can be used for variables which will have only positive and zero whole number values, within the range of the unsigned short type.

Form

unsigned-short-type
unsigned short | unsigned short int | unsigned int short
| short unsigned | short unsigned int | short int unsigned
| int short umsigned | int unsigned short

Semantics

unsigned-short-type
  1. The size of the unsigned short type is not specified exactly by the language specification; it is specified as no smaller than the unsigned char type, and no larger than the unsigned int type.
  2. Typically, for PCs, both 16 bit and 32 bit compilers assign 2 bytes (16 bits) to unsigned short type variables.
  3. The language specification does not specify an encoding, but most current computers use natural binary encoding for unsigned short integers:
    1 11111            
    5 43210 98765 43210
    Nattural Binary Magnitude
  4. A 16 bit natural binary number has a range of 0 to (232 -1), or 0 to 64,535.
  5. For any computer, the range of the short type can be found by using the symbolic constant USHRT_MAX, usually defined in the limits.h header file.

Remarks

Example

#include <stdio.h>
#include <limits.h> 

int main () {
  short unsigned c;           /* int by default        */
  short unsigned int d;       /* Explicit              */
  short int unsigned e;       /* Explicit              */
  unsigned short i;           /* int by default        */
  unsigned short int j;       /* Explicit              */
  unsigned int short k;       /* Explicit              */
  int unsigned short y;       /* Explicit              */
  int short unsigned z;       /* Explicit              */
  
  c = 3;
  d = 4;
  e = 5;
  i = 6;
  j = 7;
  k = 8;
  y = 10;
  z = 11;
  
  printf ("c is %u (%d bytes)\n", c, sizeof c);
  printf ("d is %u (%d bytes)\n", d, sizeof d);
  printf ("e is %u (%d bytes)\n", e, sizeof e);
  printf ("i is %u (%d bytes)\n", i, sizeof i);
  printf ("j is %u (%d bytes)\n", j, sizeof j);
  printf ("k is %u (%d bytes)\n", k, sizeof k);
  printf ("y is %u (%d bytes)\n", y, sizeof y);
  printf ("z is %u (%d bytes)\n", z, sizeof z);
  printf ("The range of the unsigned short int type is from %u to %u\n",
          0, USHRT_MAX);
  return 0;
}

Output