The new C + + basic type is known by temperature

Source: Internet
Author: User

C + + base type size:

In a 32-bit computer, the test results are:
sizeof (BOOL) = = 1
sizeof (char) = = 1
sizeof (short) = = 2
sizeof (int) = = 4
sizeof (LONG) = 4
sizeof (float) = = 4
sizeof (double) = = 8

Type enumeration:
Enum

Example: Define the current state of a server, respectively, start, close, pause State enum Serverstate{start, STOP, pause};

Type void*
A void pointer can point to any type of data, that is, a pointer to a void pointer that can be assigned a value using any data type, and a void pointer as a function parameter so that the function can accept pointers of any data type as arguments.

int * Pint;void *pvoid;pvoid = pint; /* but not pint= pvoid; */void * memcpy (void *dest, const void *SRC, size_t len); void * memset (void * buffer, int c, size_t num);

Amount of text
012132 (0-Opening representation 8-binary)
0x1232 (0x starting with 16 binary)
3U (unsigned int)
3L (long int)

Double the number of floating-point numbers as specified by default
2.0f
1.2e10
2.9e-3f

Usage of limits:

The template class describes arithmetic properties of built-in numerical types.  The header defines explicit specializations for the types wchar_t, bool, Char, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, float, double, and long double. For these explicit specializations, the member numeric_limits::is_specialized are true, and all relevant members have Meani Ngful values. The program can supply additional explicit specializations.    Most member functions of the class describe or test possible implementations of float. For the arbitrary specialization, no members have meaningful values. A member object that does not has a meaningful value stores zero (or false) and a member function that does not return a  Meaningful value returns Type (0).    This template class describes the numeric properties of the built-in type. The C + + standard library is explicitly wchar_t, BOOL, Char, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, The float, double, and long double provide a special type of these types. For these types, the Is_specialiZed is true, and all related members (member variables or member functions) are meaningful. This template also provides additional specificity.    Most of the member functions can be described or tested with the float type. For an arbitrary specificity, the associated member is meaningless.  A meaningless object is typically represented by 0 (or false), and a meaningless member function returns 0.

Basic usage examples of numeric_limits

#include <limits> #include <iostream>using namespace Std;int main () {cout << boolalpha;cout << " Max (short): "<< Numeric_limits<short>::max () << endl;cout <<" min ":" << numeric_ Limits<short>::min () << endl;cout << "max (int):" << Numeric_limits<int>::max () << Endl;cout << min (int): << numeric_limits<int>::min () << endl;cout << "Max (long):" <& Lt Numeric_limits<long>::max () << endl;cout << min (long): << numeric_limits<long>::min ( ) << endl;cout << endl;cout << "Max (float):" << Numeric_limits<float>::max () << Endl ; cout << "min (float):" << numeric_limits<float>::min () << endl;cout << "Max (double):" &lt ;< Numeric_limits<double>::max () << endl;cout << "min (double):" << numeric_limits< Double>::min () << endl;cout << "Max (long Double): "<< numeric_limits<long Double>::max () << endl;cout <<" min (long double): "&lt ;< Numeric_limits<long double>::min () << endl;cout << endl;cout << "is_signed (char):" < < numeric_limits<char>::is_signed << endl;cout << "is_specialized (String):" << numeric_ Limits<string>::is_specialized << Endl;}

My computer's running results

The new C + + basic type is known by temperature

Related Article

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.