无涯教程-C++ 运算符

46 阅读1分钟

操作符只是用于执行操作的符号。可以有多种类型的运算,例如算术运算,逻辑运算,按位运算等。

Cpp Operators 1

C++中运算符的优先级

将首先评估哪个运算符的运算符种类的优先级。关联性指定要评估的操作员方向,可以从左到右或从右到左。

让我们通过以下示例了解优先级:

int data=5+10*10;  

"data"变量将包含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

参考链接

www.learnfk.com/c++/cpp-ope…