C++ has a family of integer types: short, int, long, long long, plus the single-byte char types, and each can be signed or unsigned. The language only guarantees minimum sizes and an ordering, not exact sizes, so the width of a type such as long depends on the platform. For the "c++ integer types size" question, the safe answer is that you measure with sizeof or use the fixed-width types.
On most desktop and server platforms today, int is 32 bits and long long is 64 bits. long is the confusing one: 64 bits on 64-bit Linux and macOS, but 32 bits on 64-bit Windows.
The standard guarantees the following minimum widths and the ordering: short is no larger than int, which is no larger than long, which is no larger than long long.
| Type | Guaranteed minimum | Typical size today |
|---|---|---|
char | 8 bits | 8 bits |
short | 16 bits | 16 bits |
int | 16 bits | 32 bits |
long | 32 bits | 32 bits (Windows) or 64 bits (Linux, macOS) |
long long | 64 bits | 64 bits |
bool is a separate type that holds true or false. A char is an integer type that holds a character code, and signed char and unsigned char are distinct types from plain char. Whether plain char is signed is up to the implementation.
sizeof gives the size of a type in bytes (the size of char is always 1). std::numeric_limits from <limits> gives the range:
On a typical 64-bit Linux machine this prints:
Another machine may print different values for long, and that is the point: do not hard-code your own assumptions. You can also check at compile time with static_assert(sizeof(int) == 4);, which stops the build if the assumption is false.
Types are signed by default (except char, as noted). Add unsigned to get a type with no negative values and twice the positive range.
Unsigned arithmetic wraps around modulo 2 to the power of the number of bits. The subtraction does not give -2, it gives a huge number. This is well defined, but it is a common source of bugs.
Signed overflow is different: it is undefined behaviour. The compiler may assume it never happens and optimise accordingly, so a loop that relies on INT_MAX + 1 wrapping can behave unpredictably. Since C++20, the standard requires two's complement representation for signed integers, but overflow of the arithmetic itself is still undefined.
A literal has a type chosen from its value and suffix.
Prefer the digit separator ' for readability. A literal too large for int automatically takes a wider type, but write the suffix when the type matters, for example 1LL << 40.
Use these rules in everyday code:
int for ordinary counts and arithmetic where values stay well within 32 bits.std::size_t for sizes and indexes of containers, because size() returns an unsigned type.long long or a 64-bit fixed-width type for values that can exceed about 2 billion, such as file sizes or timestamps in milliseconds.-1 < 1u is false, because -1 converts to a huge unsigned value.Turn on -Wall -Wextra, which warns about many signed/unsigned comparisons.
When you assign a larger integer type to a smaller one, the value is converted. For unsigned targets it wraps; for signed targets the result of an out-of-range conversion is implementation-defined before C++20 and defined as modular wrapping from C++20 onward.
Brace initialisation rejects narrowing conversions at compile time, which is one reason to prefer {} initialisation. If you must convert, use an explicit static_cast. Since C++20, std::in_range in <utility> lets you check whether a value fits in a target type before converting, and std::cmp_less compares mixed signed and unsigned values safely.
The standard guarantees at least 16 bits. On mainstream modern platforms int is 32 bits. Use sizeof(int) to see your platform's value.
Windows 64-bit uses the LLP64 model, where long stays 32 bits. 64-bit Linux and macOS use LP64, where long is 64 bits. This is why portable code avoids long.
No. Signed overflow is undefined behaviour. Unsigned overflow wraps around and is well defined.
Use them for bit patterns and for values that are naturally non-negative and handled with care. For plain arithmetic, signed types avoid wrap-around surprises.
C++ integer types are short, int, long and long long, in signed and unsigned forms, with only minimum sizes guaranteed. Measure with sizeof and std::numeric_limits, choose int for general use and long long for big values, and remember that signed overflow is undefined while unsigned overflow wraps. Use fixed-width types when an exact size matters.