Operators and expressions in C Language
Operators and expressions
Operators in C language, also known as operators, are symbols used to perform operations between data. Operators in C language can be divided into value assignment operators, Arithmetic Operators, logical operators, Relational operators, bitwise operators, pointer operators, and member operators by operation type. operators by operation objects (also called operands) the number can be divided into the single object operator, binary operator, and three object operator.
Concatenates data or variables with operators to form a c expression. An expression is a meaningful expression that concatenates an object with an operator according to certain rules. The calculation object in an expression can be a constant, variable, function, or another expression.
Arithmetic Operations, value assignment operations, and type conversion
Arithmetic Operators and arithmetic expressions
The arithmetic operators in C language include five binary operators: plus "+", minus "−", multiplication" * ", Division"/", and remainder (Modulo) "%" and four single-object operators: auto-increment "++", auto-increment "−", single-object addition "+", and single-object subtraction (arithmetic inversion) "− ", in addition, there are Parentheses "()" operators that can be used to change the order of operations.
The auto-increment "++" is divided into the front ++ and the back ++ plus the front ++, that is, adding 1 first and then adding 1 with the original value;
The auto-increment "--" is divided into the front -- and the back -- the front -- is to first subtract 1 and then use the original value and then minus 1;
An expression composed of Arithmetic Operators, values, variables, and so on is called an arithmetic expression.
Value assignment operator and value assignment expression
The value assignment operation is used to change the value of a variable. The C language provides a simple assignment operator "=" and 10 composite assignment operators: + =, −=, * =,/=, % =, <=, >=, & =, ^ =, and | =.
Type conversion Operator
In expressions, when different types of data are mixed, the C language will automatically convert their types. This conversion is generally "up, that is, the data type that occupies a small bucket is converted to the data type that occupies a large bucket.
Logical operators and expressions www.2cto.com
Logical operations are completed by logical operators. There are three logical operators:
& Logic and
| Logical or
! Non-logical
The logic operation rules are as follows:
A & B/* The operation result is true (1) only when the values of a and B are true. Otherwise, the operation result is false (0 )*/
A | B/* The calculation result is false (0) only when the values of a and B are false. Otherwise, the result is true (1 )*/
! A/* When a is true, the result is false (0). When a is false, the result is true (1 )*/
When compared with other types of operators that have previously been learned, it has the following relationships:
Non-logical! > Arithmetic Operators> Relational operators> logic and &> logic or |> value assignment operators
Conditional operation
Conditional operators are the only three-object operators and the most special operators in C language.
The format of conditional operators is as follows:
Expression 1? Expression 2: expression 3
It means that if expression 1 (condition) returns true, the result of the entire operation is the value of expression 2; if expression 1 (condition) returns false, the result of the entire operation is the value of expression 2.
Sizeof Operator
The sizeof operator is used to calculate the size of its operands, that is, the number of nodes occupied by it in memory.
From 10-3G-He Jinchao