Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

short — short integer type

short is a signed integer type equivalent to short int. It need not occupy exactly two bytes.

Version: C23; repository compiler flag, production runtime not attested

Syntax

short name;
short int name;
signed short name;
unsigned short name;

short, short int, signed short, and signed short int denote the same type. unsigned short is a distinct unsigned type.

Do not assume exactly 16 bits or a smaller size than int. <limits.h> supplies the limits SHRT_MIN, SHRT_MAX, and USHRT_MAX.

In arithmetic, short values undergo promotion to int. The example stores the result in int; %hd prints the short value.

Examples

#include <stdio.h>

int main(void)
{
    short temperature = -12;
    short change = 5;
    int result = temperature + change;

    printf("%hd %d\n", temperature, result);
    return 0;
}

Result

-12 -7

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources