CPP variables and basic types (1)

Source: Internet
Author: User

1.unsigned Long is equivalent to unsigned int and can be abbreviated to unsigned.

2.llp64 the length of each type of compilation model:

Environment: Win-64/vs 2013

Code:

1Std::cout <<"size of (int):"<<sizeof(int ) 2<<"Byte."<<Std::endl;3Std::cout <<"size of (long):"<<sizeof(Long )4<<"Byte."<<Std::endl;5Std::cout <<"size of (long):"<<sizeof(Long Long )6<<"Byte."<<Std::endl;7Std::cout <<"size of (unsigned int):"<<sizeof(unsignedint ) 8<<"Byte."<<Std::endl;9Std::cout <<"size of (unsigned long):"<<sizeof(unsignedLong)Ten<<"Byte."<<Std::endl; OneStd::cout <<"size of (unsigned long long):"<<sizeof(unsignedLong Long) A<<"Byte."<< Std::endl;

Results:

4. Select the type of experience:

A. The unsigned type is chosen when it is clear that the value cannot be negative;

B. The actual application of int and long is the same size;

The default type of C.char may be unsigned or signed type, depending on the machine, so it should be clearly specified to be unsigned char or unsigned char;

D. Perform floating-point arithmetic using double. Because the float is usually not accurate and the double-precision floating-point number and the single-precision floating-point number calculation cost is similar;

E.long double provides the precision in general is not necessary, moreover it brings the computation time consumption also cannot neglect;

CPP variables and basic types (1)

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.