C 运算符C Operators

C 运算符是 C++ 的内置运算符的子集。The C operators are a subset of the C++ built-in operators.

有三种类型的运算符。There are three types of operators. 一元表达式包括附加到操作数的一元运算符或后跟表达式的 sizeof 关键字。A unary expression consists of either a unary operator prepended to an operand, or the sizeof keyword followed by an expression. 该表达式可以是变量的名称,也可以是强制转换表达式。The expression can be either the name of a variable or a cast expression. 如果表达式是强制转换表达式,则它必须括在括号中。If the expression is a cast expression, it must be enclosed in parentheses. 二进制表达式包括通过二元运算符联接的两个操作数。A binary expression consists of two operands joined by a binary operator. 三元表达式包括通过条件表达式运算符联接的三个操作数。A ternary expression consists of three operands joined by the conditional-expression operator.

C 包含以下一元运算符:C includes the following unary operators:

符号Symbol nameName
- ~ !- ~ ! 求反和补数运算符Negation and complement operators
* & 间接寻址运算符和 address-of 运算符Indirection and address-of operators
sizeof Size 运算符Size operator
+ 一元加运算符Unary plus operator
++ --++ -- 一元递增和减量运算符Unary increment and decrement operators

二元运算符从左至右关联。Binary operators associate from left to right. C 提供了以下二进制运算符:C provides the following binary operators:

符号Symbol nameName
* / %* / % 乘法运算符Multiplicative operators
+ -+ - 相加运算符Additive operators
<< >> 移位运算符Shift operators
< > <= >= == !=< > <= >= == != 关系运算符Relational operators
& | ^& | ^ 位运算符Bitwise operators
&& ||&& || 逻辑运算符Logical operators
, 有序评估运算符Sequential-evaluation operator

Microsoft 16 位 C 编译器的早期版本所支持的基本运算符 (:>) 在 C 语言语法摘要中进行了介绍。The base operator (:>), supported by previous versions of the Microsoft 16-bit C compiler, is described in C Language Syntax Summary.

条件表达式运算符的优先级低于二进制表达式的优先级并与其在右关联上存在差异。The conditional-expression operator has lower precedence than binary expressions and differs from them in being right associative.

使用运算符的表达式还包括赋值表达式,该表达式使用一元或二元赋值运算符。Expressions with operators also include assignment expressions, which use unary or binary assignment operators. 一元赋值运算符是增量 (++) 和减量 (--) 运算符;二元赋值运算符是简单赋值运算符 (=) 和复合赋值运算符。The unary assignment operators are the increment (++) and decrement (--) operators; the binary assignment operators are the simple-assignment operator (=) and the compound-assignment operators. 每个复合赋值运算符是另一个二元运算符与简单赋值运算符的组合。Each compound-assignment operator is a combination of another binary operator with the simple-assignment operator.

请参阅See Also

表达式和赋值Expressions and Assignments