Program to find Range of Data Types in C++
Notes:
Program to Find and Print Range of Data Types in C++
- Data type indicates type of data
- Data type indicates the amount of memory to be allocated for specific type of data
- Data type indicates the range of values possible to store in that specific type of allocated memory.
W.K.T. There are 7 primitive data types available in C++ language
1. int : 4 or 2 bytes : (-2,147,483,648 to 2,147,483,647) OR (-32768 to 32767)
2. float : 4 bytes : 1.17549e -38 to 3.40282e+38
3. double : 8 bytes : 2.22507e -308 to 1.79769e+308
4. char : 1 byte : -128 to 127
5. wchar_t : 2 bytes : 0 to 65,535
6. bool : 1 byte : 0 or 1 ( note: any non zero value is converted to 1 )
7. void : 1 or 0 byte : value less or nothing
W.K.T:
1 byte = 8 bits, 2 bytes = 16 bits, 4 bytes = 32 bits, 8 bytes = 64 bits
Example Code:
#include <iostream>
#include<limits.h>
#include<float.h>
using namespace std;
int main()
{
cout << "int min =" << INT_MIN << endl; // -2147483648
cout << "int max =" << INT_MAX << endl; // 2147483647
cout << "float min =" << FLT_MIN << endl; // 1.175494e-038
cout << "float max =" << FLT_MAX << endl; // 3.402823e+038
cout << "double min =" << DBL_MIN << endl; // 2.225074e-308
cout << "double max =" << DBL_MAX << endl; // 1.797693e+308
cout << "char min =" << CHAR_MIN << endl; // -128
cout << "char max =" << CHAR_MAX << endl; // 127
cout << "wchar_t min=" << WCHAR_MIN << endl; // 0
cout << "wchar_t max=" << WCHAR_MAX << endl; // 65535
cout << "bool min =" << false << endl; // 0
cout << "bool max =" << true << endl; // 1
cout << endl;
cout << "float precision=" << FLT_DIG << endl; // 6
cout << "double precision=" << DBL_DIG << endl; // 15
cout << "long double precision=" << LDBL_DIG << endl; // 18
return 0;
}