`signed` — C++ Keyword

`signed` — C++ Keyword

The signed keyword in C++: explicitly marks an integer type as signed.

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.

signed

Explicitly marks an integer type as signed (capable of storing negative values). For int, short, long, and long long, signed is the default and redundant. For char, the signedness is implementation-defined, so signed char is explicit.

Syntax

signed char   sc;    // explicitly signed 8-bit
signed short  ss;    // same as short
signed int    si;    // same as int
signed long   sl;    // same as long

Example

#include <print>

int main() {
    signed char sc = -42;
    signed int  si = -1'000;

    std::println("{}", sc);    // -42
    std::println("{}", si);    // -1000

    // Contrast with unsigned:
    unsigned char uc = static_cast<unsigned char>(-1);
    std::println("{}", uc);    // 255 (wraps around)
}

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