sizeof operator to get the number of bytes in memory of various data types--gyy collation

Source: Internet
Author: User

C + + does not specify the storage size of various data types in memory, depending on the different compiler, to know the current compiler to the various data types allocated size, can be obtained through the sizeof operator.

Use Method 1:

sizeof (data type)

Use Method 2:

sizeof (variable name or constant name or expression)

sizeof (int)

Or

int A;

sizeof (a)

[CPP]View PlainCopy
  1. Spatial allocation of data types
  2. #include <iostream>
  3. Using namespace std;
  4. int main ()
  5. {
  6. cout<<"vc++6.0 compilation environment, the amount of memory space (in bytes) of various data type variables" <<endl;
  7. cout<<"sizeof (int)" <<sizeof (int) <<endl;
  8. cout<<"sizeof (short int)" <<sizeof (short) <<endl;
  9. cout<<"sizeof (long int)" <<sizeof (long) <<endl;
  10. cout<<"sizeof (unsigned int)" <<sizeof (unsigned) <<endl;
  11. cout<<"sizeof (unsigned short int)" <<sizeof (unsigned ) <<endl;
  12. cout<<"sizeof (unsigned long int)" <<sizeof (unsigned long) <<endl;
  13. cout<<"sizeof (char)" <<sizeof (char) <<endl;
  14. cout<<"sizeof (float)" <<sizeof (float) <<endl;
  15. cout<<"sizeof (double)" <<sizeof (double) <<endl;
  16. cout<<"sizeof (long Double)" <<sizeof (long Double) <<endl;
  17. return 0;
  18. }

Run results



sizeof operator to get the number of bytes in memory of various data types--gyy collation

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.