//1. The program tries to avoid relying on the implementation of the environmental behavior. For example, if the size of an int is treated as a known value that is determined to be constant, then such a program is called non-portable. typedefintInt32;//using a similar typedef, you can effectively solve the migration problem//2. When doing arithmetic operations, pay attention to the promotion of the signed type to the unsigned type Long LongValue = (int)-1+ (unsignedint)0;//value = 4294967295//3. The value of a line such as 42 is called a literal constant, so the value is known at a glance. Each literal constant corresponds to a data type, and the form and value of the literal constant determines its data type. //4. Generalized escape sequence: The form is \x (note is lowercase x) followed by a hexadecimal number, or \ followed by 1, 2 or 3 octal digits, where the number portion represents the value of the character corresponding Char*STR0 ="\x31";//STR0 = "1" Char*STR1 ="\x31";//str0 = "X31" Char*STR2 ="\0615";//str2 = "15" Note there are only the first 3 numbers and \ constitute escape sequences//5. You can change the default type by adding a prefix or suffix to the literal value, the string is prefixed, and the arithmetic type is the suffix intValue0 =sizeofL'a';//value0 = 2 L prefix indicates wide character corresponds to wchar_t type intValue1 =sizeof~0U;//value1 = 4 u or u suffix for shaping represents a minimum match type of unsigned intvalue2 =sizeof~0L;//value2 = 4 L or L (letter L) for shaping indicates that the minimum match type is long intValue3 =sizeof~0LL;//value2 = 8 ll or ll (letter L) for shaping indicates that the minimum match type is long long intValue4 =sizeof 0.1;//Value4 = 8 default to double storage of floating-point numbers intValue5 =sizeof 0.1F;//Value5 = 4 f or f suffix for floating-point expression float intValue6 =sizeof 0.1L;//Value6 = 8 L or l suffix for floating-point expression long doubleunsignedLong LongValue7 = ~0LL;//Value7 = 0xffffffffffffffff Note LL indicates that the minimum match type is a long long and not a suffix such as long long, U l, and so on. UnsignedLong LongValue8 =0xFFFFFFFFFFFFFFFFL;//Value8 = 0xffffffffffffffff again emphasizes the minimum match type. //6. Definitions and variables outside of any function body are initialized to 0, variables defined in the function body are not initialized, and any attempt to access and copy variables that are not initialized will be faulted//The 7.c++ distinguishes the declaration from the definition, and the declaration makes the name known to the program. Defines the entity responsible for creating the names associated with the name. Variables can be defined only once, but can be declared multiple times. extern intVALUE0;//Statement intvalue1;//definition extern intvalue2 =0;//definition//8. Variable naming specification: variable names usually start with lowercase, and user-defined types generally start with uppercase. For variables with multiple words, the hump naming method is applied. //9. Scope Operator:: There are 3 ways to use:: Name;//Global Scope class:: Name;//class Scope namespace:: Name//namespace Scope//10. A declaration statement consists of a basic data type and a list of declarators immediately following it. Each declarator names a variable and specifies that the variable is a type that is related to the base data type. In the same declaration statement, the basic data types are the same, but the declarators are not necessarily the same. //base type: is a type specifier that can be decorated with a const, before the declarator in the declaration statement. The base type provides the most common data types that are used to build the declarator. //declarator: is part of the declaration, including the name and type modifiers of the defined object. where type modifiers (such as const,registe, etc.) are optional. intValue0 =0;//in this definition statement, int is the base data type and VALUE0 is the declarator. The result of this declaration statement is that the declarator value is specified as an int type. int*pvalue0, value1;//in this definition statement, 2 variables of different types are defined. Pvalue0 is a int* type whose type modifier * is part of the declarator, value1 is of type int, and their base data type is int.
//11. Reference: Another name is given to the object, the reference must be initialized, and the reference cannot be re-bound to another object. The reference itself is not an object. You cannot define a referenced reference, you cannot store reference types in a container, and you cannot define an array of element types as reference types. //The reference type is strictly matched to the object it is bound to, with two exceptions: 1. When initializing a constant reference, it is allowed to use any expression that can be converted to that reference type as the initial value. 2. The parent class reference can accept child class objects. DoubleDATA0 =3.14; Const int&data1 = DATA0;//legal, but Data1 and data0 have different addresses.//12. Pointer: is a composite type that points to another type. It is an object in itself. The void* pointer is a special kind of pointer that can be used to store the address of any object and cannot be referenced by the void* pointer. //The pointer type must match the object exactly, but there are two exceptions://1. A pointer to a constant is allowed to point to a very const object. However, this assignment has a precondition: only one layer of indirection: int* can be converted to a const int *, and cannot be converted from INT * * to const INT * *//2. The parent pointer can point to the child class object. intNumber =0; Const int*pnumber0 = &Number ; int*ConstPNumber1 = &number;//the symbol closest to PNumber1 is const, meaning that PNumber1 itself is a constant whose type is determined by the remainder of the declarator. //13. By default, the const object is set to valid within the file. When a const variable with the same name appears in multiple files, it is equivalent to defining these separate variables separately in different files. If a const variable is defined in the header file, then multiple source files containing the header file will define their own independent const variable. //if you want to share the const variable between files, define it in a source file, and make an extern declaration in the header file, all the source files that contain this header file will share a const variable. //Const is classified as the top-level const and the underlying const. The top-level const can indicate that any object is a constant, while the underlying const represents the object that the pointer refers to as a constant. Because the reference is not an object, the const of the reference type is the underlying const. //there is a significant difference between the top-level const or the underlying const when performing object copies. Where the top-level const is unaffected. On the other hand, when the underlying const object performs a copy operation, the object required to be copied and copied must have the same underlying const qualification or the data type of two objects to be converted. //Const is a type modifier Const int*p0 = nullptr;//The const here is the underlying const int*ConstP1 = nullptr;//The const here is the top-level const Const intCount =0;//The const here is the top-level const//14. Type aliases: Use the keyword typedef. typedefint*Pint; intNdata =0; ConstPint PData = &nData;//equivalent to: int *const pData = &nData; Note point: Pint is used in the declaration, its basic data type is a pointer, if written as const int *pdata = &nData; Its basic data type is int, * becomes Part of the declarator. //pData = nullptr; //error C3892: "PData": Cannot assign a value to a constanttypedefclassB {}b; //B is the alias of B//15.auto: Let the compiler infer the type of the variable by its initial value. Obviously, the variables defined by auto must have an initial value and must have the same basic type. //Auto The inferred type is not exactly the same as its initial value in the following cases, the compiler appropriately changes the result type to make it more compliant with the initialization rule//A: The compiler refers to the type of the object as the type of auto. //B:auto ignores the top-level const and preserves the underlying const//C:auto will convert the function name to the corresponding function pointer type//D:auto will convert the array name to the corresponding pointer type//16.decltype: You want to infer the type of the variable you want to define from the expression, but you do not want to initialize the variable with the value of the expression. In this procedure, you only have to type the expression and not actually evaluate the value of the expression. //Decltype does not perform conversions that are performed by the compiler in auto. //If the expression used by Decltype is not a variable, DECLTYPE returns the type corresponding to the expression. If the evaluation result of an expression is an lvalue, decltype acts on the expression (not a variable) to get a reference type. //Lvalue: When an object is used as an lvalue, the identity of the object (in-memory position) is used//rvalue: When the object is used as the right value, the value of the object (content) is used//assignment operator: A very left value is required as its left operator object, and the resulting result is also an lvalue//take address: acts on an lvalue operand, returns a pointer to the operand, which is an rvalue//Dereference and subscript operators: Evaluation results are left values//forward Increment decrement operator: evaluates to left value//Post increment decrement operator: evaluates to the right value intNNumber0 =Ten; int*pnnumber0 = &NNumber0; Decltype (NNUMBER0) nNumber1; //nNumber1 is of type intDecltype (PNNUMBER0) nNumber2;//nNumber2 for int* typeDecltype ((NNUMBER0)) NNumber3 = NNumber0;//nNumber3 for int& typeDecltype (*PNNUMBER0) nNumber4 = NNumber0;//nNumber4 for int& type//17. The structure and class of the class body can be followed by the definition of its object classa {} A; //A is an object of Class A//18. When the preprocessor sees the # include tag, it replaces # include with the contents of the specified header file//You typically use #ifdef #endif to prevent duplicate inclusions. //preprocessing variables disregard the scope restrictions in the C + + language #define Indicate the acceptance of the following name, and define the name as a preprocessor variable, commonly capitalized. //Pre-processor is responsible for replacing the preprocessing variable in the program with its true value before the program compiles//19. The array name is the same as an array name in the numeric value, but in a different sense, the former is the first address of a list, which is a pointer to an array intarray[Ten] = {0}; intSIZE0 =sizeofArray//size0 = intSize1 =sizeof(&array);//size1 = 4//20. Constant expression: is the expression that the value does not change, and the result can be computed during compilation intFun () {return Ten;} Const intNValue0 =Ten;//constant-expression Const intNValue1 = NValue0 +1;//constant-expression intNValue2 =Ten;//is not a constant expression because: the value of value2 can change Const intNValue3 = Fun ();//is not a constant expression because the value of VALUE3 cannot be obtained at compile time
C++primer Chapter II