C + + programming language Exercise 4.5

Source: Internet
Author: User

The C + + standard library provides limit values for numeric types through template numeric_limits. Using this template, you can improve the portability of the program to a certain extent.

#include <iostream> #include <limits>using std::cout;using std::endl;using std::numeric_limits;int Main ()  {cout<< "The min of char is:" << (int) numeric_limits<char>::min () <<endl;  cout<< "The Max of char is:" << (int) Numeric_limits<char>::max () <<endl;  cout<< "The Min of short is:" <<numeric_limits<short>::min () <<endl;  cout<< "The max of short is:" <<numeric_limits<short>::max () <<endl;  cout<< "The min of int is:" <<numeric_limits<int>::min () <<endl;  cout<< "The max of int is:" <<numeric_limits<int>::max () <<endl;  cout<< "The Min of Long is:" <<numeric_limits<long>::min () <<endl;  cout<< "The max of Long is:" <<numeric_limits<long>::max () <<endl;  cout<< "The Min of float is:" <<numeric_limits<float>::min () <<endl; cout<< "The max of float is:" <<numeriC_limits<float>::max () <<endl;  cout<< "The Min of double is:" <<numeric_limits<double>::min () <<endl;  cout<< "The max of Double is:" <<numeric_limits<double>::max () <<endl;  cout<< "The min of long double is:" <<numeric_limits<long double>::min () <<endl;  cout<< "The max of long Double is:" <<numeric_limits<long Double>::max () <<endl;  cout<< "The min of unsigned is:" <<numeric_limits<unsigned>::min () <<endl; cout<< "The max of unsigned is:" <<numeric_limits<unsigned>::max () <<endl;}

Operation Result:

[Email protected] cpp]$ g++-o 4.5./4.5.cpp[[email protected] cpp]$./4.5 the Min of char is: -128 the max of Char Is:1  The Min of is: -32768 the max of is:32767 the min of int is: -2147483648 the max of int is:2147483647 the Min of Long is: -9223372036854775808 the max of Long is:9223372036854775807 the min of float is:1.17549e-38 the max of Float is:3.40282e+38 the min of double is:2.22507e-308 the max of double is:1.79769e+308 the min of long double is:3.3 621e-4932 the max of long double is:1.18973e+4932 the min of unsigned is:0 the max of unsigned is:4294967295




C + + programming language Exercise 4.5

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.