`short` — C++ Keyword

`short` — C++ Keyword

The short keyword in C++: a signed integer type at least 16 bits wide.

How to use this reference page

Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.

  • Scan the top of the page first to identify the primary types, functions, or algorithm families involved.
  • Use the nearby-page links when your question is really about a companion header, related algorithm family, or broader subsystem.
  • Validate tricky behavior with a small compileable example before relying on memory for details like invalidation, ordering, allocation, or lifetime rules.

short

Shorthand for short int. A signed integer type guaranteed to be at least 16 bits wide. On virtually all modern platforms it is exactly 16 bits.

Syntax

short s;
short int s;
unsigned short us;
signed short ss;

Example

#include <print>
#include <climits>

int main() {
    short s = 32767;
    std::println("{}", s);            // 32767

    unsigned short us = 65535u;
    std::println("{}", us);           // 65535

    std::println("min: {} max: {}", SHRT_MIN, SHRT_MAX);
    // min: -32768 max: 32767

    // Integer arithmetic promotes short to int
    short a = 100, b = 200;
    auto sum = a + b;                 // type is int, not short
    std::println("{}", sum);          // 300
}

Notes

Example in practice

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;
}