In C #, there are a total of 38 commonly used operators. Based on the features of their operations and their priority, I classify them into seven levels for ease of memory: 1. Unit operators and parentheses. 2. Regular Arithmetic Operators. 3. Displacement operator. 4. Comparison operators. 5. logical operators. 6. Various assignment operators. 7. Right-bit (suffix) Unit operator.
1. At this level, there are ++, -- (as prefix), (), +,-(as Unit operator), and ),! ,~. All operators at this level are cell operators, except for the pair of special parentheses that have changed any operation Priority. It can be seen that in the definition expression, the priority of those cell operators is very high, probably because they all act directly on the operands. Only the priority of two cell operators is not in the first level, and they appear later for special reasons.
2. In general Arithmetic Operators, we often use *,/, %, +, and-. They are also in a high position because they are used a lot.
3. This level is two special bitwise operators. <and> these operators have the highest priority except regular operators, it may be because, in comparison with comparison operators and logical operators, these operators perform numerical calculations.
4. Comparison operators, including <,>, <=, >=, =, and ,! =, There are a total of six. Here there is a feature, which is smaller than or greater.
5. There are four types of logical operators and logical operators, but the "Non" operators used for units are listed in the front, so only &, ^, |, add two additional operators &, |, to improve code efficiency. There are five operators.
6. Value assignment operator, which has the largest number of values at this level. It is almost a binary operator that has appeared before. Adding the "=" sign here becomes a value assignment operator. First of all, of course, the most basic value assignment operator "=", followed by the evolution of regular Arithmetic Operators "* =,/=, % =, + =,-= ", they are in the same order as regular arithmetic operators, and then shift operators and logical operators are arranged in the order they evolved, <=, >>=, & =, ^ =, and | = ". Because the data type of the result produced by the comparison operator is different from the Data Type of its operation number, they do not have the corresponding value assignment operator.
7. the last level is the ++ and -- Extensions of the two final Unit operators ,--. They appear to supplement = and -- of the two prefix versions (the priority of the two versions is too high, and people need two lower-priority versions) to facilitate expression design, so these two priorities must be at the end.
Then, the priority order of the 38 operators can be written as follows: (whether horizontal or vertical, the higher the priority, the higher)
Level 1: ++, -- (as the prefix), (), +,-(when used as the Unit operator ),! ,~.
Level 2: *,/, %, +, and ,-.
Level 3: <,>.
Level 4: <,>, <=,> =, = ,! =.
Level 5: &, ^, |, &, |.
Level 6: =, * =,/=, % =, + =,-=, <=,> =, & =, ^ =, | =.
Level 7: ++, -- (suffix ).
This is only a summary of my learning C #. I am not sure about the division methods at all levels and the priority of operators. I just want to share my opinion with you.