📅  最后修改于: 2020-10-16 06:20:13             🧑  作者: Mango
运算符只是用于执行操作的符号。可以有多种类型的运算,例如算术运算,逻辑运算,按位运算等。
有以下几种类型的运算符可以用C语言执行不同类型的运算。
将首先评估哪个运算符的运算符种类的优先级。关联性指定要评估的运算符方向,可以从左到右或从右到左。
让我们通过以下示例了解优先级:
int data=5+10*10;
“数据”变量将包含105,因为*(乘数运算符)在+(加法运算符)之前求值。
C++运算符的优先级和关联性如下所示:
Category | Operator | Associativity |
---|---|---|
Postfix | () [] -> . ++ – – | Left to right |
Unary | + – ! ~ ++ – – (type)* & sizeof | Right to left |
Multiplicative | * / % | Left to right |
Additive | + – | Right to left |
Shift | << >> | Left to right |
Relational | < <= > >= | Left to right |
Equality | == !=/td> | Right to left |
Bitwise AND | & | Left to right |
Bitwise XOR | ^ | Left to right |
Bitwise OR | | | Right to left |
Logical AND | && | Left to right |
Logical OR | || | Left to right |
Conditional | ?: | Right to left |
Assignment | = += -= *= /= %=>>= <<= &= ^= |= | Right to left |
Comma | , | Left to right |