an operator is a symbol that tells the compiler to perform a specific arithmetic or logical operation. the C language has a wide range of operations, and almost all the basic operations except control statements and input and output are treated as operators. There are three main categories: arithmetic operators, relational operators, and logical operators. In addition, there are operators to accomplish special tasks.
Let's take a look at an example:
#include <stdio.h>
int main () {
int a=10,b=1,c=2;
A=b=c;
printf ("12+3*5=%d\n", 12+3*5);
printf ("a=%d, c=%d\n", A, c);
return 0;
}
Run Result:
12+3*5=27
a=2, c=2
1) for the expression 12+3*5, it is obvious that the multiplication operation, the calculation 3*5, the result is 15, then the addition operation, the calculation 12+15, the result is 27. In other words, the multiplication priority is higher than the addition, to be calculated first, which is the same as the rules in mathematics.
The priority is what operator is executed first when more than one operator is present in the same expression. If you do not want to follow the default rule, you can add (), for example (12+3) *5 result is 75, (2+5) * (10-4) results are 42. In most cases, their rules and math are the same.
2 to the statement assignment statement A=b=c, first executes the b=c, then executes the a=b, instead of the reverse, this indicates that the assignment operator = has the right binding.
The so-called binding is when an operator occurs multiple times, which operator is executed first. To the right of the first to the right of the binding, the first to perform the left is called the left binding.
The concepts of Expressions (Expression) and statements (Statement) are not explicitly defined in the C language:
An expression can be regarded as a calculated formula, often composed of data, variables, operators, such as 3*4+5, A=c=d, etc., and its result must be a value;
The scope of the statement is more extensive, not necessarily a calculation, not necessarily a value, can be an operation, a function, select structure, loop, and so on.
It is noteworthy that the end of a semicolon is often called a statement, not an expression, such as 3*4+5; a=c=d;
3) like + 、-、 *,/Such operators, it has data on both sides, such as 3+4, a*3, and so on, there are two operands, we call such operators are binocular operators. The Monocular operators and the three-mesh operator are also explained later.
The above is the C language operator priority and the combination of knowledge collation, I hope to learn C language students help.