Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

int16_t — an exactly 16-bit signed integer type

int16_t from <stdint.h> names a signed integer type with exactly 16 bits. Its availability depends on the implementation.

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

Syntax

#include <stdint.h>
int16_t name = value;

int16_t is a typedef name declared in <stdint.h>, not a keyword. It has exactly 16 bits, no padding bits, and a range of −32768 through 32767.

The type is optional: implementations must provide it when they support a suitable integer type. Test availability with #ifdef INT16_MAX. When at least 16 bits suffice, use the required int_least16_t instead.

Do not assume sizeof(int16_t) == 2: a C byte need not contain 8 bits. Exact width does not guarantee wrapping signed arithmetic. The example casts to int to match %d.

Examples

#include <stdint.h>
#include <stdio.h>

#ifndef INT16_MAX
#error "int16_t is required"
#else
int main(void)
{
    int16_t temperature = -125;
    printf("%d\n", (int)temperature);
    return 0;
}
#endif

Result

-125

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