Data Type Ranges and their macros in C++ - GeeksforGeeks

29 May, 2017
Most of the times, in competitive programming, there is a need to assign the variable, the maximum or minimum value that data type can hold, but remembering such a large and precise number comes out to be a difficult job. Therefore, C++ has certain macros to represent these numbers, so that these can be directly assigned to the variable without actually typing the whole number. List of some of them are mentioned below.
Data Type                              Range                      Macro for min value           Macro for max value
char                                -128 to +127                        CHAR_MIN                      CHAR_MAX
short char                          -128 to +127                       SCHAR_MIN                     SCHAR_MAX
unsigned char                         0  to 255                             0                        UCHAR_MAX

short int                         -32768 to +32767                      SHRT_MIN                      SHRT_MAX
unsigned short int                    0  to  65535                          0                        USHRT_MAX 
int                          -2147483648 to +2147483647                  INT_MIN                       INT_MAX
unsigned int                          0  to  4294967295                     0                         UINT_MAX
long int            -9223372036854775808 to +9223372036854775807        LONG_MIN                      LONG_MAX
unsigned long int                     0  to  18446744073709551615           0                        ULONG_MAX 
long long int       -9223372036854775808 to +9223372036854775807       LLONG_MIN                     LLONG_MAX
unsigned long long int                0  to  18446744073709551615           0                       ULLONG_MAX

float                        1.17549e-38 to  3.40282e+38                 FLT_MIN                       FLT_MAX
float(negative)             -1.17549e-38 to -3.40282e+38                -FLT_MIN                      -FLT_MAX
double                      2.22507e-308 to  1.79769e+308                DBL_MIN                       DBL_MAX
double(negative)           -2.22507e-308 to -1.79769e+308               -DBL_MIN                      -DBL_MAX

// C++ code to demonstrate the macros for data types#include<iostream>#include<limits.h> // for int,char macros#include<float.h> // for float,double macrosusing namespace std;int main(){  // Displaying ranges with the help of macroscout << "char ranges from : " << CHAR_MIN << " to " << CHAR_MAX;cout << "\n\nshort char ranges from : " << SCHAR_MIN << " to " << SCHAR_MAX;cout << "\n\nunsigned char ranges from : " << 0 << " to " << UCHAR_MAX;  cout << "\n\n\nshort int ranges from : " << SHRT_MIN << " to " << SHRT_MAX;cout << "\n\nunsigned short int ranges from : " << 0 << " to " << USHRT_MAX;cout << "\n\nint ranges from : " << INT_MIN << " to " << INT_MAX;cout << "\n\nunsigned int ranges from : " << 0 << " to " << UINT_MAX;cout << "\n\nlong int ranges from : " << LONG_MIN << " to " << LONG_MAX;cout << "\n\nunsigned long int ranges from : " << 0 << " to " << ULONG_MAX;cout << "\n\nlong long int ranges from : " << LLONG_MIN << " to " << LLONG_MAX;cout << "\n\nunsigned long long int ranges from : " << 0 << " to " << ULLONG_MAX;  cout << "\n\n\nfloat ranges from : " << FLT_MIN << " to " << FLT_MAX;cout << "\n\nnegative float ranges from : " << -FLT_MIN << " to " << -FLT_MAX;cout << "\n\ndouble ranges from : " << DBL_MIN << " to " << DBL_MAX;cout << "\n\nnegative double ranges from : " << -DBL_MIN << " to " << +DBL_MAX;  return 0;  }
Output:
char ranges from : -128 to 127

short char ranges from : -128 to 127

unsigned char ranges from : 0 to 255


short int ranges from : -32768 to 32767

unsigned short int ranges from : 0 to 65535

int ranges from : -2147483648 to 2147483647

unsigned int ranges from : 0 to 4294967295

long int ranges from : -9223372036854775808 to 9223372036854775807

unsigned long int ranges from : 0 to 18446744073709551615

long long int ranges from : -9223372036854775808 to 9223372036854775807

unsigned long long int ranges from : 0 to 18446744073709551615


float ranges from : 1.17549e-38 to 3.40282e+38

negative float ranges from : -1.17549e-38 to -3.40282e+38

double ranges from : 2.22507e-308 to 1.79769e+308

negative double ranges from : -2.22507e-308 to 1.79769e+308

This article is contributed by Manjeet Singh .If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
cpp-data-types
C Language
C++
Competitive Programming
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
rand() and srand() in C/C++
fork() in C
Left Shift and Right Shift Operators in C/C++
Command line arguments in C/C++
Function Pointer in C
Vector in C++ STL
Inheritance in C++
Initialize a vector in C++ (6 different ways)
Map in C++ Standard Template Library (STL)
C++ Classes and Objects