Introduction to C language (2) Statements and operators
The basic statements in C language are similar to those in Java.
- Loop statements (do while, while,)
- Conditional statements (if, if-else, switch)
- Goto statement (for example, defining an Exit mark outside the loop:; you can use goto Exit in the loop; jumping out of the loop)
[Plain]
- For (int I = 0; I <5; I ++)
- {
- If (I = 2) goto exit;
- Printf (I = % d, I );
- }
- Exit :;
- Printf (admin );
Arithmetic Operators
- + Addition Operators
- -Subtraction operator or negative operator
- * Multiplication Operator
- /Division Operator
- % Modulo operator, or the remainder operator, must be an integer on both sides of %
Relational operators
- <Less than Operator
- <= Less than or equal to the operator
- > Greater than Operator
- > = Operator greater than or equal
- = Equals Operator
- ! = Not equal to operator
No boolean type in C Language
In C language, if the result of the relational operation is true, 1 is returned. If false, 0 is returned.
Int a1 = 5> 4; // 1
Int a2 = 5 <4; // 0
* Note that in C, any non-0 value is true. Only 0 value is assumed as if (-1 ){}
If (a = 0 ){}
In the C language, you can save the result of the relational operation. Therefore, the following statement is valid:
Int a = 10;
A> 10;
A = 0;
Logical operators
- & Logic and operators
- | Logic or operator
- ! Logical non-Operator
There are only two results for the logical operation: true if it is true, 1 is returned; false if it is not true, 0 is returned.
Compound assignment operator
- + = Add the value assignment operator. For example, a + = 3 + 1 is equivalent to a = a + (3 + 1)
- -= Minus value assignment operator. For example, a-= 3 + 1 is equivalent to a = a-(3 + 1)
- * = Multiplication and value assignment operator. For example, a * = 3 + 1 is equivalent to a = a * (3 + 1)
- /= Except the value assignment operator. For example, a/= 3 + 1 is equivalent to a = a/(3 + 1)