Operator indicates the type of the code
Binary operator
Bitwise
There are 6-bit computing:
- And operation &
- | Or operation
- ^ XOR operation
- ! NOT operation (complement)
- >> right shift operation
- << left shift operator
And calculating (&)
Binocular operations. When two bits are set (= 1), the result is equal to 1, the other results are equal to zero.
> 1 & 1 == 1
> 1 & 0 == 0
> 0 & 1 == 0
> 0 & 0 == 0
OR (|)
Binocular operations. When two bits are set (= 1), the result is equal to 1, the other results are equal to zero.
> 1 & 1 == 1
> 1 & 0 == 0
> 0 & 1 == 0
> 0 & 0 == 0
Exclusive-OR operation (^)
Binocular operations. When two bits are not equal, the result is 1, and 0 otherwise.
> 1 ^ 1 == 0
> 1 ^ 0 == 1
> 0 ^ 1 == 1
> 0 ^ 0 == 0
Non-operation (!)
Unary. Inverted bit value, 0 is set to 1, 0 or 1 is set. Will refer to the use of non-positioning operation is cleared, the remaining positions 1. Operation and non-independent numerical values.
Shift operator (<< and >>)
bit value of bits specified moving in one direction. >> shift right operator moves from high to low, the operator moves from left << low-order bit.
&,&&,|,||
&& quite a switch statement, that if the value is false && front so he would not continue behind the expression; and & why regardless of the value front, behind it is always executed statement. && and || boolean logic operations are to return to bool value. & Bitwise operators is, it will be calculated either side of these operations are then ANDed; & bit operation 0101 is used to handle such a binary character. Boolean logical operators && (short-circuit operation), as long as the side of the operation result is false, it will immediately return to false; && boolean arithmetic so treated is true and false.
By the same token, || also Boolean operator, as long as the result of the operation side is true, it returns true immediately.
Relational Operators
https://baike.baidu.com/item/%E5%85%B3%E7%B3%BB%E8%BF%90%E7%AE%97%E7%AC%A6/352774
Arithmetic Operators
The multiplication operator [*], division operator [/], take the operator I [%], [+] the addition operator, the subtraction operator [-].
Assignment operator
https://baike.baidu.com/item/%E8%B5%8B%E5%80%BC%E8%BF%90%E7%AE%97%E7%AC%A6/2482721
comma operator
https://baike.baidu.com/item/%E9%80%97%E5%8F%B7%E8%BF%90%E7%AE%97%E7%AC%A6/7959271
Unary operator
Unary operator means a desired variable operator, i.e. only a few of them in the arithmetic operation, called unary operator, wherein the non-logical operators:!, Bitwise operators: ~, from the operational operators: +, - and the like.
Ternary operator
? For the conditional expression b x: y, the first calculation condition b, then determination. If b is true, the calculated value, the calculation result is a value x of x; otherwise, y value, the calculation result for the value of y.
A conditional expression will not only calculate x, and calculate y. The conditional operator is right-associative, that is, from right to left on the calculated packet. For example, a b:? C d: ? E will be a b:? (C d: ? E) performed.
** <Expression 1> <Expression 2>:?; "?" <Expression 3> operator is the meaning of: 1 to evaluate the expression, and if true, the expression 2 is performed, and returns the expression results of formula 2; and 1 if the expression is false, the expression 3 is performed, and returns the result of expression 3. **
it can be understood as the result of a condition:? 2 results inside? No format is required. Can also be understood as the condition is satisfied, the condition is the result of the establishment of 1, otherwise the result 2.
Note: In the C language, Results Type 1 and 2 must be the same.
a b:? c method is simple to understand:
if(a) { return b; } else { return c; }
In general, binding ternary operator is right-associative.
Operator Precedence