INTEGER TYPE MODIFIERS & TYPICAL BIT SIZES (x86-64):
┌───────────────────────────┬──────────┬──────────────────────────────────────────┐
│ Type │ Size │ Numerical Range │
├───────────────────────────┼──────────┼──────────────────────────────────────────┤
│ short int │ 16 bits │ -32,768 to 32,767 │
│ unsigned short int │ 16 bits │ 0 to 65,535 │
│ int (signed) │ 32 bits │ -2,147,483,648 to 2,147,483,647 │
│ unsigned int │ 32 bits │ 0 to 4,294,967,295 │
│ long int │ 32/64 bit│ Architecture Dependent │
│ long long int │ 64 bits │ -9,223,372,036,854,775,808 to ...75,807 │
│ unsigned long long int │ 64 bits │ 0 to 18,446,744,073,709,551,615 │
└───────────────────────────┴──────────┴──────────────────────────────────────────┘Type Modifiers in C++: short, long, signed, and unsigned
Direct Answer & Core Concept
Detailed Explanation & Mechanics
1. Integer Storage and Ranges:
2. Unsigned Wrap-Around Behavior:
Unsigned arithmetic is defined by the standard to wrap modulo 2^N on overflow/underflow, whereas signed overflow is Undefined Behavior (UB).
Runnable Code Example: Type Modifiers in C++
C++20 / C++23#include <iostream>
#include <limits>
int main() {
short sVal = 32000;
unsigned short usVal = 65000;
long long bigNumber = 9000000000000000000LL;
unsigned int wrapped = 0;
wrapped = wrapped - 1; // Wraps around to UINT_MAX
std::cout << "short: " << sVal << " (bytes: " << sizeof(sVal) << ")";
std::cout << "unsigned short: " << usVal << "";
std::cout << "long long: " << bigNumber << " (bytes: " << sizeof(bigNumber) << ")";
std::cout << "Unsigned underflow wrap (0 - 1): " << wrapped << "";
return 0;
}