0

How to print the range of int,float, double datatpye in c++

10th Aug 2018, 1:52 AM
Ajay
Ajay - avatar
2 Antworten
+ 5
Simply add #include <limits> to the top of the code, then make some query using std::numeric_limits<T>::min(); std::numeric_limits<T>::max(); for getting the lower and upper bound of the arithmetic type ¹ T, respectively. ●●Example●● cout << numeric_limits<int>::min() << endl; cout << numeric_limits<int>::max() << endl; _____ ¹ https://en.cppreference.com/w/cpp/types/numeric_limits
10th Aug 2018, 6:57 AM
Babak
Babak - avatar
0
int Typical Range = -2147483648 to 2147483647 float Typical Range = +/- 3.4e +/- 38 (~7 digits) double Typical Range = +/- 1.7e +/- 308 (~15 digits) -------------------------------------------------- #include <iostream> using namespace std; int main() { cout << "Size of int : " << sizeof(int) << endl; cout << "Size of float : " << sizeof(float) << endl; cout << "Size of double : " << sizeof(double) << endl; return 0; }
10th Aug 2018, 2:03 AM
Imade Andika Suwartama
Imade Andika Suwartama - avatar