Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C++

signed — signed integer type specifier

The signed keyword specifies a signed integer type. Used alone, signed means int; with short, int, long, and long long it is redundant. However, signed char is a distinct type from both char and unsigned char.

Version: C++23; repository compiler flag, production runtime not attested

Syntax

signed name; signed int name; signed short [int] name; signed long [int] name; signed long long [int] name; signed char name;

signed is a type specifier, not a sign-changing operator. A signed integer type can represent negative values, zero, and positive values. The declarations signed balance;, signed int balance;, and int balance; give the variable the same type.

Valid combinations include signed short, signed int, signed long, signed long long, and signed char; combinations with short or long may also include int. Square brackets in the displayed syntax indicate an optional element — they are not typed into the code. You cannot form types such as signed float or combine signed with unsigned.

char, signed char, and unsigned char are three distinct types. Whether plain char has a signed range is implementation-defined; signed char always has a signed range. Do not assume that int is exactly 32 bits or that signed char is exactly 8 bits: the standard specifies minimum widths, not identical sizes on every platform.

Signed integer arithmetic overflow causes undefined behavior, not guaranteed wraparound. The example uses small values within the required ranges. static_cast<int>(adjustment) prints a number rather than using a character stream overload. The supplied document is an evolving standard draft, not a frozen C++23 publication.

Examples

#include <iostream>
#include <type_traits>

int main() {
    static_assert(std::is_same_v<signed, int>);
    static_assert(!std::is_same_v<signed char, char>);

    signed balance = -12;
    signed int change = 5;
    signed char adjustment = -3;

    std::cout << balance + change << '\n';
    std::cout << static_cast<int>(adjustment) << '\n';
}

Result

-7
-3

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