10-12c# Basics-Operator
Pre-class assignments: the name and age of the number in the class are written and aggregated.
I. Classification of Operators
1, mathematical operators (7)
1) + (plus)
Cases:
2)-(minus)
Cases:
3) * (multiplication sign)
Cases:
4)/(Division sign)
Cases:
5)% (number, whichever is the remainder)
Cases:
6) + + (increment character) automatic operation +1
? prefix increment operator:
Cases:
Postfix increment operator:
Cases:
Although the results are the same, the difference is that:
? ,//prefix increment operator: The first operation, then the assignment, and the last semicolon is the result of the assignment.
int y=++x;
equivalent to x=x+1;
int y=x;
Cases:
',///suffix increment operator: First assignment, after operation, and final semicolon after the result of assignment
int y=x + +;
Equivalent to int y=x;
x=x+1;
Cases:
7)--(decrement character) automatic operation minus 1
The calculation method is the same as the increment operator, where only the difference between the prefix decrement operator and the Postfix decrement operator is emphasized:
Exercise 1: Calculate the area of the Circle:
2, relational operators (6). Returns only true or FALSE.
1) = =
2)! = (not equal to)
3) <
4) >
5) <=
6) >=
2, logical operators (3).
1) and (&&) equal to and, several conditions must be met before execution
2) or (| | Equivalent or, only one or a few of these conditions can be satisfied.
3) Non-(! Equivalent to No, as long as the condition does not satisfy the return of true, applied in front of the parentheses of the expression.
4. Other operators
? assignment operators
1) = (equals)
2) + = (not equal to)
3)-=
4) *=
5)%=
6)/=
?:< Span style= "font-family: ' Song body '; font-size:16pt; Mso-spacerun: ' Yes '; >x;// x>12, so X=X-12; x=x.
Example: Hourly System
Exercise 2: Judging whether a student's score is passed (60 points)
Exercise 3: Judge whether the number within 0-100 is prime?
Exercise 4: Determine whether the integer within 0-200 is related to the whole ;
Precedence of operators (top-down)
1)!
2) Arithmetic operators
+ +,--
*,/,%
+,-
3) Relational operators
<,>,<=,>=
= =,!=
4) Logical operators
&&
||
Cases:
10-12c# Basics-Operator