2.1 Arithmetic types
BOOLCharCharacter8wchar_t Wide character -char16_t Unicode character -char32_t Unicode character + Short ShortInteger -intInteger -Long LongInteger +Long Long -floatSingle-precision floating-point6significant digitsDouble Double-precision floating-pointTensignificant digitsLong DoubleExtended-precision floating-pointTenSignificant digits
char_t type guarantees that any character in the machine's maximum extended character set can be stored
char16_t and char32_t for Unicode character set services
Bit bit, bytes byte, Word Word
1byte=8bit
Word size is machine-related, typically 4byte
Signed and unsigned
For char types, it is possible that different machines are now different, some are signed, some are unsigned, so you should specify the symbols when you need to perform mathematical arithmetic operations with char.
When you cast a negative number to an unsigned digit, the result is a modulo with the unsigned number.
For example, converting 1 to unsigned short:unsigned short is 65536, then the result of unsigned short (-1) is 65535
A deeper understanding is that when a negative number is converted to an unsigned digit, it is directly the sign bit 1 of its complement, as the normal unsigned digital interpretation, and its in-memory data does not change, as follows:
cout<<Short (0xffff) <<endl; // output-1 Short (0xffff) <<endl; // Output 65535 Short (Short (0xffff)) <<endl; // Output 65535
In-system representation
150 binary, 158 binary, 0x15 hex
String can be written in a branch
cout<<" name Study No. \" " Wang 50,125";
Escape sequences
\ immediately after 1-3 octal digits
\x followed by a 1-* hexadecimal number
Literal value and Prefix
Prefix
U Unicode 16 Character char16_t
U Unicode 32 Character char32_t
L Wide character wchar_t
U8 UTF-8 char[] String
Suffix
u/u unsigned
L/L Long
Ll/ll Long Long
f/f float
L/L long Double
Types can be combined, such as 42ULL for unsigned long long
2.2 Variables
Variable initialization
intValue1 =0;intvalue2 = {0};intValue3 (0);intvalue4{0};//The above four effects are the sameVector<int> value5{1,2,3,4,5};//stored 1 2 3 4 5vector<int> Value6 (Ten,-1);//stored 10-1
Built-in types (int, double, char) are not initialized when they are defined without a given initial value.
Accessing global variables
int value=ten; int Main () { int value=5; overrides the global variable value int newvalue=::value; use:: Access global Variables }
2.3 Composite Types
Reference reference
int &rValue=value; A variable or an object's nickname, occupying the same piece of memory, must be initialized when declaring a reference, and cannot be changed to a referenced variable or object after initialization.
Pointer pointer
int *pvalue=&value; Declares a variable that stores the address of another variable.
Null pointer:
int *pvalue=nullptr;
int *pvalue=0;
int *pvalue=null; Need include<cstdlib>
void * pointer
Any type can be used with the void* pointer, which can be thought of as the corresponding piece of memory area void* pointer.
2.4 Const Qualifier
Pointers and const
Const intValue = +;//the memory corresponding to value cannot be changed//pointer to constant pointer to constConst int*cpvalue = &temp;//cpvalue corresponding memory can be changed (can be re-pointed to another variable), but temp cannot be changed by Cpvalue (the variable pointed to cannot be changed)//constant Pointer const Pointint*ConstPcvalue = &temp;//Pcvalue The corresponding memory cannot be changed (cannot be re-pointed to another variable), temp can be changed by Pcvalue (the variable pointed to can be changed)//constant pointer to constantConst int*ConstCpcvalue = &temp;//are not allowed to change
constexpr and constant Expressions
A constant expression is a constant of a value that can be determined at compile time.
For example, the bottom two is a constant expression:
Const int - ; Const int 1;
However, there are times when it is not possible to determine whether a statement is a constant expression, which can be constexpr for a variable declaration, and the compiler verifies that it is not a constant expression:
int 1; // An expression can be compiled only if MF is a compile-time determined value
2.5 Types of processing methods
Type aliases
typedef double Wages, *pwages;//wages is the alias of Double, Pwages is the alias of double*
Using db = Double; supported in the//C++11
Auto
Auto item = v1 + v2;//The compiler infers the type of item
Decltype
Select and return the data type of the operand
Decltype (f ()) sum = x;
A reference type that represents the operand when the operand is enclosed in parentheses
Decltype ( (f () )) sum = x;
Chapter 2nd variables and basic built-in types