Data Types and value ranges in C (MIN, MAX)
C Has a number of data-types. The actualy size of these values and thus the range veriables with various types can hold is not defined in C. These are machine-dependent. That is they will be (probably) different on a 32 bit machine and a 64 bit machine. They can also depend on the Operating System etc.
name | description |
---|---|
char | character - a single byte (between -128 and 127) |
int | integer (16 bit, 32 bit?) |
short | short integer |
long | long integer |
float | floating point (typically 32 bit) |
double | double-precision floating point |
#include <stdio.h>
#include <limits.h>
int main() {
printf("INT_MIN %12d\n", CHAR_MIN);
printf("INT_MIN %12d\n", CHAR_MAX);
printf("INT_MIN %12d\n", SHRT_MIN);
printf("INT_MAX %12d\n", SHRT_MAX);
printf("INT_MIN %12d\n", INT_MIN);
printf("INT_MAX %12d\n", INT_MAX);
// printf("UINT_MIN %d", UINT_MIN); // It would be 0
printf("UINT_MAX %12u\n", UINT_MAX);
// Note: using %d it would print -1
}
On my 64bit machine running Ubuntu Linux:
INT_MIN -128
INT_MIN 127
INT_MIN -32768
INT_MAX 32767
INT_MIN -2147483648
INT_MAX 2147483647
UINT_MAX 4294967295