One, arithmetic operator 1. Addition operator +
* In addition to addition operations, you can also indicate a plus sign: +521
2. Subtraction operator-
* In addition to subtraction operations, you can also indicate a minus sign: 741
3. Multiplication operator *
* Please note that the symbol is not X, but rather *
4. Division operator/
* Please note that the symbol is not ÷, but/
* Integer divided by integer or integer, value 1/2 is not 0.5 but 0.
5. Area operator%
* Residual is the remainder after dividing two integers
*% can only be integers on both sides
* Positive and negative depending on% left of the value of the symbol
6. Assignment operator =
* Simple assignment: int a =10,a=10+5
* Match assignment: int a+=4+5
7. Self-increment self-reduction
* Self-increment operator: + +, such as a++ equivalent to A=a+1
* Self-decrement operator:---, such as a--equivalent to A=a-1
Supplement: The difference between a++ and ++a
+ + before is a plus one in the use of a;++ after the first use a, and then add one.
Two, relational operators (comparison operators) 1. Relational operators
There are six kinds of = =,! =, <, <=, >, >=.
2. True and False
1> in C language, the condition is called "true", the condition is not set up called "false", therefore the judgment condition is established, is the judgment condition "true and false".
2> How to judge True and false? C language rules, any value is true and false, any non-0 value is "true", only 0 is "false". In other words, 18, 18, 4.5, 4.5, etc. are all "true" and 0 are "false".
3. Relationship Comparison
There are only 2 operations of the 1> relational operator: If the condition is true, the result is 1, which is "real", and if the condition is not true, the result is 0, or "false".
4. Use note
* the precedence of = =,! = in the relational operator equals,<, <=, >, >=, and the precedence of the former is lower than the latter: 2==3>1
* The associative direction of the relational operator is "left to right": 4>3>2
* The precedence of the relational operator is less than the arithmetic operator: 3+4>8-2
third, logical operators
* The result of the logical operation is only 2: "True" is 1, "false" is 0
1.&& Logic and
1> format: Condition a && condition b
2> operation Results
Only when condition A and condition B are set up, the result is 1, which is "true" and the rest is 0, which is "false".
3> Operation Process
Always first judge the condition a, if the condition A is established, continue to judge the condition B; If condition A is not established, then the condition B will not be judged.
4> the C language stipulates that any value other than 0 is "true" and only 0 is "false". Therefore, the logical operation also applies to numerical values.
2.| | Logical OR
1> use a variety of
Condition a| | Condition b
2> operation Results
When a condition A or B, as long as there is a set up, the result is 1, that is, "true", when the condition A, B is not set, the result is 0, that is, false.
3> Operation Process
Always first determine whether the condition A is set up, if the condition A is established, will not judge the condition B; If condition A is not established, then go back to judge condition B.
3.! Logical Non-
1> using formats
! Condition A
2> operation Results
In fact, the condition A is reversed: if condition A is established, the result is 0, that is, "false", if condition A is not established, the result is 1, that is, "true".
3> Note
* Logical non-operators can be used multiple times consecutively:! (4>2) The result is 0, is "false",!! (4>2) The result is 1, is "true",!!! (4>2) The result is 0, which is "false"
* C Language: Any non-0 value is "true", only 0 is "false". Therefore, a non-0 value is not logical! The result of the operation is 0, the value of 0 is logical non! The result of the operation is 1.! 5,!6.7 、!-9 results are 0,!0 results of 1
4. Priority level
1. Precedence Order of logical operators: parentheses () > minus sign->! > Arithmetic operators > Relational operators > && > | |
Four or three mesh operator 1. Format
Condition A? Statement 1: Statement 2
2. Results of the operation
If condition A is true, statement 1 is executed and statement 2 is executed if condition A is not true
C language-basic operators