Let's summarize the common operation identifiers today.
One, arithmetic operator.
First look at what the arithmetic identifiers are: + 、-、 *,/,%.
These operators are the most basic operators and do not introduce too much. Note, however, that "%" can only be used for integer types.
Second, the shift operator.
The shift operator has two:>> (right shift operators), << (left shift operator).
Special attention is paid to the right-shift operation in two situations:
1, arithmetic right shift;
2, logical shift.
Arithmetic right shift refers to: The binary number has positive and negative points, the complement should pay attention to the sign bit;
Logical shift situation refers to: do not need to consider the problem of symbols, directly fill 0.
Here is an example of a code:
#include <stdio.h>int main () { ten; printf ("%d\n1); System ("pause"0;}
Its result output is 5. Special attention is needed here,
1. The shift operator cannot directly assign a value to change the variable.
If you need to change variables, you need to enter:a>>=1;
2, left to move the equivalent of/2;
The right shift action is equivalent to * *.
Three, bit operators.
Bitwise operators include:& (bitwise AND), | (bitwise OR), ^ (bitwise XOR).
These three operators are also very simple, in the previous exchange two of the contents of the reference to the usage.
It is important to note that these three operator operations must be integers.
Four, assignment operator.
The assignment operator is often present in the previous program code with the following operators: =, + =, and so on.
Note that in successive assignments, you should assign a value from right to left, for example:
a=x=y+1;
The value of a at output should be y+1.
Five, monocular operator.
The Monocular operators are:! (logical anti-action, non-), & (address character), sizeof (for length), ~ (bitwise negation), + + 、--、 *, (type), and so on.
It is important to note that:
1, & is the address character,%p print address.
2, sizeof () is an operator, not a function!
3, the front and rear of + +. To illustrate:
#include <stdio.h>int main ()//+ + after { int0 ; = a++; printf ("a=%d,b=%d\n", A, b); System ("pause"); return 0 ;}
Results obtained: a=11,b=10.
#include <stdio.h>int main ()//+ + front { int0 ; = + +A; printf ("a=%d,b=%d\n", A, b); System ("pause"); return 0 ;}
Results obtained: a=11,b=11.
4, * Here is the indirect access operator, mainly related to pointers.
5, (type) is a forced type conversion operator, such as forcing a floating-point number to be converted to an integral number:
#include <stdio.h>int main () { int0; float 3.14 ; = (int) F; printf ("num=%d\n", num); System ("pause"); return 0 ;}
The result of this output: num=3.
Vi. relational operators.
The main relational operators are: = =, >=, <=.
It mainly appears in the comparison of the conditions, such as: If statement, for Loop, and so on.
Seven, conditional operators.
1, Exp1? EXP2:EXP3;
For example, explain the above statement:
intMain () {intA=Ten, b=0; if(A >5) b=3; Elseb =-3; printf ("b=%d\n", B); System ("Pause"); return 0;}
When a=10 is determined by the IF condition, the value of B is 3.
When a=-10, the value of B is-3.
If the above statement can be expressed as:
#include <stdio.h>int main () { int a=, b=0; 5 3 :-3; printf ("b=%d\n", b); System ("pause"); return 0 ;}
The results are the same in both ways.
2, EXP1, EXP2, EXP3
For example, explain:
#include <stdio.h>int main () { int a=1, b=2; int Ten 1 ); printf ("c=%d\n", c); System ("pause"); return 0 ;}
The arithmetic rule for a comma conditional sentence is to go from left to right, and the result is the result of the last expression.
The result output is c=13.
Eight, the other operators.
1. Subscript reference operator []: more commonly seen in arrays. Example: Arr[2].
Special Note: arr[2] is equivalent to * (arr+2).
2, Function call operator (): This operator is very common, do not do too much explanation.
3. Struct member access operator . and: More commonly seen in structs. In the subsequent review of the data structure we are in detail.
Summarizes the--c language operators.