About C++ basic knowledge, you must know these professional terms(4)

The road is hindered and long, and the line is coming. Keep your head down and work hard, if you don't call it, it's a blockbuster! Come on, Sao Nian!

1 Introduction

  Based on "C++ Primer 5th Edition", Chapter 4 "Expressions" summarized;

  Tip: Be good at using shortcut keys to quickly search for relevant content! Ctrl + F

2 Chapter Summary

   The C++ language provides a rich set of operators and defines the operations that these operators perform when they act on operands of built-in types. In addition, the C++ language also supports the mechanism of operator overloading, allowing us to define the meaning of operators when they act on class types. Chapter 14 explains how to define operators that act on user types.

  For expressions containing more than one operator, the key to understanding its meaning is to understand precedence, associativity and order of evaluation. Each operator has its corresponding precedence and associative law. The precedence specifies the way of combining operators in compound expressions, and the associative law explains how to combine operators when their precedence is the same.

  Most operators do not specify the order in which the operands are evaluated: the compiler has the freedom to choose whether to evaluate the left operand first or the right operand first. Generally speaking, the order of evaluation of operands has no effect on the final result of the expression. However, if two operands point to the same object and one of them changes the value of the object, it will cause serious defects that are not easy to find in the program.

  Finally, operands are often automatically converted from primitive types to some associated types. For example, the small integer type in the expression is automatically promoted to the large integer type. Both built-in types and class types involve type conversion issues. If necessary, we can also explicitly cast.

3 Glossary

  • 算术转换(arithmetic conversion)

  Convert from one arithmetic type to another arithmetic type. In the context of binary operators, in order to preserve precision, arithmetic conversions usually convert smaller types to larger types (for example, integers to floating point types).

  • 结合律(associativity)

  Specifies how operators with the same precedence are combined together. The associative law is divided into the left associative law (operators combine from left to right) and right associative law (operators combine from right to left).

  • 二元运算符(binary operator)

  There are two operators involved in the operation.

  • 强制类型转换(cast)

  An explicit type conversion.

  • 复合表达式(compound expression)

  An expression containing more than one operator.

  • const_cast

  A type of coercion involving const. Convert the underlying const object to the corresponding non-constant type, or perform the opposite conversion.

  • 转换(conversion)

  The process of changing one type of value to another type of value. The C++ language defines conversion rules for built-in types. Class types can also be converted.

  • dynamic_cast

  Used with inheritance and runtime type recognition. See section 19.2 (page 730).

  • 表达式(expression)

   The lowest level of calculation in a C++ program. Expressions apply operators to one or more operands, and each expression has a corresponding evaluation result. The expression itself can also be used as an operand, and then a compound expression that evaluates multiple operators is obtained.

  • 隐式转换(implicit conversion)

  Type conversion performed automatically by the compiler. If the expression requires a certain type and the operand is of another type, the compiler will automatically convert the operand to the required type as long as the rules allow it.

  • 整型提升(integral promotion)

  The process of converting a smaller integer type to the closest larger integer type. Regardless of whether it is really needed, small integer types (ie short, char, etc.) will always be promoted.

  • 左值(lvalue)

  Refers to expressions that evaluate to objects or functions. A non-constant lvalue representing an object can be used as the left operand of the assignment operator.

  • 运算对象(operand)

  Expressions perform operations on certain values, and these values ​​are the operands. An operator has one or more related operands.

  • 运算符(operator)

  The symbol that determines the operation performed by the expression. The C++ language defines a set of operators and explains the meaning of these operators when they act on built-in types. C++ also defines the precedence and associativity of operators and the number of operands handled by each operator. Operators can be overloaded to handle class types.

  • 求值顺序(order of evaluation)

  Is the evaluation order of the operands of an operator. In most cases, the compiler can arbitrarily choose the order in which the operands are evaluated. But the operand must get the evaluation result before the operator. Only the four operators &&, ||, condition and comma clearly stipulate the order of evaluation.

  • 重载运算符(overloaded operator)

  The redefined version applicable to the class type for a certain operator. Chapter 14 will introduce the method of overloading operators.

  • 优先级(precedence)

  Specifies the execution order of different operators in compound expressions. Compared with low-priority operators, high-priority operators are combined more closely.

  • 提升(promoted)

  See integral promotion.

  • reinterpret_cast

  Interpret the content of the operand into another type. This type of coercion is essentially machine-dependent and very dangerous.

  • 结果(result)

  The value or object obtained by calculating an expression.

  • 右值(rvalue)

  Refers to an expression whose result is the value rather than the location of the value.

  • 短路求值(short-circuit evaluation)

  It is a proper noun that describes the execution process of the logical AND operator and the logical OR operator. If the result of the entire expression can be determined based on the first operand of the operator and the evaluation ends, the second operand will not be evaluated at this time.

  • sizeof

  It is an operator that returns the number of bytes required to store an object. The type of the object may be a given type name, or it may be determined by the return result of an expression.

  • static_cast

  Explicitly perform some well-defined type conversion, often used to replace the type conversion implicitly performed by the compiler.

  • 一元运算符(unary operators)

  Operator with only one operand involved in the operation.

  • , 运算符(, operator)

  The comma operator is a binary operator that evaluates from left to right. The result of the comma operator is the value of the operand on the right, and the result of the comma operator is the lvalue if and only if the operand on the right is an lvalue.

  • ? : 运算符(? : operator)

  Conditional operator, which provides an if-then-else logical expression in the following form

cond ? exprl : expr2;

  If the condition cond is true, evaluate expr1; otherwise, evaluate expr2. The types of expr1 and expr2 should be the same or can be converted to the same type. Only one of expr1 and expr2 will be evaluated.

  • && 运算符(&& operator)

  The logical AND operator, if both operands are true, the result is true. Only when the left operand is true will the right operand be checked.

  • & 运算符(& operator)

  The bitwise AND operator generates a new integer value from two operands. If the corresponding bits of the two operands are both 1, the bit in the result obtained is 1; otherwise, the bit in the result obtained is 0.

  • ^ 运算符(^ operator)

  The bitwise XOR operator generates a new integer value from two operands. If the bits corresponding to the two operands have and only one is 1, the bit in the result obtained is 1; otherwise, the bit in the result obtained is 0.

  • || 运算符(|| operator)

  Logical OR operator, any operand is true, the result is true. Only when the left operand is false will the right operand be checked.

  • | 运算符(| operator)

  The bitwise OR operator generates a new integer value from two operands. If at least one of the bits corresponding to the two operands is 1, the bit in the result obtained is 1; otherwise, the bit in the result obtained is 0.

  • ++ 运算符(++ operator)

  Increment operator. There are two forms: pre-version and post-version. The pre-increment operator gets an lvalue, which adds 1 to the operator and gets the changed value of the operand. The post-increment operator gets an rvalue, which adds 1 to the operator and gets a copy of the original, unchanged value of the operand. Note: Even if the iterator does not define the + operator, there will be the ++ operator.

  • -- 运算符(-- operator)

  Decrement operator. There are two forms: pre-version and post-version. The pre-decrement operator gets an lvalue, which subtracts 1 from the operator and gets the changed value of the operand. The post-decrement operator gets an rvalue, which subtracts 1 from the operator and gets a copy of the original, unchanged value of the operand. Note: Even if the iterator does not define-operator, there will be-operator.

  • << 运算符(<< operator)

  The left shift operator shifts the (possibly promoted) copy of the value of the left operand to the left, and the number of bits shifted is determined by the right operand. The operand on the right must be greater than or equal to 0 and less than the number of digits of the result. The operand on the left should be an unsigned type. If it is a signed type, once the movement changes the value of the sign bit, an undefined result will be produced.

  • >> 运算符(>> operator)

  Right shift operator, except that the direction of movement is opposite, other properties are similar to left shift operator. If the operand on the left is a signed type, the content of the newly shifted-in is different depending on the implementation. The newly shifted-in bits may all be 0, or they may be copies of the sign bit.

  • ~ 运算符(~ operator)

  The bit negation operator generates a new integer value. Each bit of this value is exactly the opposite of the corresponding bit of the operand (possibly after promotion).

  • ! 运算符(! operator)

  The logical negation operator reverses the Boolean value of its operand. If the operand is false, the result is true; if the operand is true, the result is false.

If the content of the article is wrong, please comment / private message a lot of advice! If you think the content of the article is not bad, remember to click the four links (like, bookmark, leave a message, follow), if you can click a follow, that is the greatest encouragement to me, and it will be the motivation for my creation, thank you !

Guess you like

Origin blog.csdn.net/fighting_boom/article/details/108985868