Fundamentals of C + + programs: variables (1)
In the last blog post we've probably seen what a C + + program should look like, and then we're going to start learning C + +, a broad and profound programming language. What is the basis of the C + + language? Answer: "Variable".
To figure out what is a variable, first understand the data type of the variable, the data type tells us the meaning of the data, and the operations we can perform on the data (important). C + + supports a wide range of data types it defines several basic built-in types, and also provides a mechanism for customizing data types. This article mainly describes the built-in types.
One: basic arithmetic type
The arithmetic types are introduced first, with two types: integer (both character and Boolean) and floating-point. The following table lists the arithmetic types for standard C + +.
| Type |
Meaning |
Minimum size |
| bool |
Boolean type |
Not defined |
| Char |
Character |
8 Guests |
| wchar_t |
Wide character |
16 Guests |
| wchar16_t |
Unicode characters |
16 Guests |
| wchar32_t |
Unicode characters |
32 Guests |
| Short |
Short-integer |
16 Guests |
| Int |
Integral type |
16 Guests |
| Long |
Long integer type |
32 Guests |
| Long Long |
Long integer type |
64 guests |
| Float |
Single-precision floating-point type |
6-digit valid digits |
| Double |
Double-precision floating-point type |
10-digit valid digits |
| Long double |
Extended Progress Floating-point |
10-digit valid digits |
Note: 1. Char is a standard character set in standard C + +, others such as wchar_t, wchar16_t, and wchar32_t are extended character sets. The former ensures that any character of the machine's maximum extended character set can be accommodated, and the latter is served for the Unicode character set.
2. In addition to bool and char other integral types can represent different lengths of integers, C + + stipulates that int is at least as large as short, long is at least as large as int, long long (c++11 newly defined data type) is at least as large as long.
3. Float, a float is usually represented by 32 bits, a double is represented by 64 bits, and a long double is commonly used for 96-bit or 128-bit representations (one word = 4 bytes = 32 bits).
Two: Signed type and unsigned type
Integral types (except for Boolean and extended characters) can be divided into signed and unsigned type with no symbols, with symbol types representing positive, negative, and zero. Unsigned types may not represent negative numbers. int, short, long, long long are all signed, and an unsigned type can be obtained by adding unsigned to these signed data types.
1#include <iostream>2 using namespacestd;3 intMain ()4 {5 intA=0;6Unsignedintb=1;7 LongC=4;8UnsignedLongD= the;9}
Note that the character types are divided into three types: char, signed char, unsigned char three type, and Char is represented as signed and unsigned entirely by the compiler.
Note: Unicode character set: Unicode (Uniform Code, universal Code, single code) is a character encoding used on a computer. Unicode is created to address the limitations of traditional character encoding schemes, which set a uniform and unique binary encoding for each character in each language to meet the requirements of cross-language, cross-platform text conversion and processing. Research and development began in 1990, officially announced in 1994. When programming, be sure to note the character set used (especially ANSI and Unicode).
C + + Learning notes: Variables