In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces how to define the C++ data type in C++. The content is very detailed. Interested friends can use it for reference. I hope it can be helpful to you.
This paper focuses on the C++ data type, and the C++ data type in C++ defines the way the compiler stores information in memory. In different development environments, variables can be assigned any numerical type. The translator can consider allocating space according to the length and type of numbers.
On the other hand, you have to declare the variable type before using the variable: int x1 = 1 position int x = 1000 position float y = 3.14 × long z = 457000; in this way, the compiler can do type checking to ensure that everything goes well when the program runs. Improper use of data types can lead to compilation errors or warnings that can be analyzed and corrected before running.
Some data types are signed and unsigned. Signed (signed) C++ data types can contain positive and negative numbers, while unsigned (unsigned) data types can only contain positive numbers. Table 1.1 lists the data types, amount of memory required, and possible ranges of values in C++.
Char 1-128126 unsigned char 10 to 255short 2-32768 to 32767 unsigned short 20 to 65535 long 4-2147483648 to 2147483648 unsigned long 40 to 4294967295 int 4 with long unsigned int 4 with unsigned long float 4 1.2E-38 to 3.4E381 double 8 2.2E-308 to 1.8E3082 bool 1 true or false
As you can see from the table above, int is the same as long. So why does C++ still distinguish between the two C++ data types? Actually, this is a legacy problem. In a 16-bit programming environment, int requires 2 bytes and long requires 4 bytes. In a 32-bit programming environment, both types of data are stored in 4 bytes. C++Builder generates only 32-bit programs, so int is the same as long.
It shows that Bool is a real data type in C++ Builder and BorLand C++ 5.0. Some C++ compilers have the Bool keyword, then Bool is not a true data type. Sometimes Bool is just a typedef, making Bool equivalent to int.
Typedef actually creates aliases that allow the compiler to equate one symbol with another. The syntax for typedef is as follows: typedef int Bool; tells the compiler that Bool is an alias for int. Indicates that only double and float data types use floating-point numbers (numbers with decimal points). Other C++ data types only involve integer values.
Although the integer data type can also specify a value with a decimal point, the decimal part is discarded and only the integer part is assigned to the integer variable, for example: int x = 3.75; the resulting x is 3. Note that this integer value is not rounded, but discards the decimal part. By the way, most Windows programs rarely use floating-point numbers. C++ can convert between different C++ data types if necessary.
For example: short result;long num1 = 200 th long num2 = 200 X result = num1 * num2; here I want to assign the product of two long integers to a short integer. Although this formula uses a mixture of two data types, C++ can be converted.
What will be the result of the calculation? The result will surprise you, it's 25536, which is the result of wrop. As can be seen from Table 1.1, the value of * * for short integers is 32767. What if you add 1 to the value of * *? What I got was 32768. This is actually the same as the car odometer from 99999 to 00000. To illustrate this, enter and run the program contained in listing 1.3 below.
On how to define C++ C++ data type to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.