`signed` — C++ Keyword
`signed` — C++ Keyword
The signed keyword in C++: explicitly marks an integer type as signed.
`signed` — C++ Keyword
The signed keyword in C++: explicitly marks an integer type as signed.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
signedExplicitly 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.
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
#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)
}
signed char when you need a guaranteed signed 8-bit integer, or use std::int8_t.std::int32_t with explicit checks.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;
}