The ranges of data types in C define the minimum and maximum values they can hold, depending on their size, and whether they are signed or unsigned. For example, int typically ranges from -2,147,483,648 to 2,147,483,647 for signed, and 0 to 4,294,967,295 for unsigned on a 32-bit system. The size of data types is also dependent on the compiler.
Ranges of Data Types
C does not specify how many bytes should be allocated to data types, this depends on the compiler. Here we discuss about most common ranges used by GCC compiler.
Data Types | Number of bits | Ranges |
|---|---|---|
char | 8 | -128 to 127 (-27 to 27 -1) |
unsigned char | 8 | 0 to 255 (0 to 28-1) |
short | 16 | -32768 to 32767 (-215 to 215-1) |
int | 32 | -2.14x109 to -2.14x109 (-231 to 231-1) |
unsigned int | 32 | 0 to 4.9x109 (0 to 232-1) |
long long | 64 | -9.2x1018 to 9.2x1018 (-263 to 263-1) |
unsigned long long | 64 | 0 to 1.8x1019 (0 to 264-1) |
float | 32 | ±1.8x10-38 to ±3.4x1038 (±2-126 to ±2128) |
double | 64 | ±2.23 x 10-308 to ±1.80x10308(±21028 to ±21024) |
bool | 8 | 0 to 1 |
Notes:
- Negative numbers are store by using 2's complement.
- When you compare floating or decimal number so we careful because thats not 100% correct.
- Decimal numbers are calculate in the form of mantisa and exponent both parts calculated seprately.
- Representing and performing arithmatic operations on floating points is done under the guidlines of IEEE 754.
- If a value exceeds or is below the range of a data type, signed integers cause undefined behavior, unsigned integers wrap around, and floating-point values become infinity or lose precision.