Basic operator and expression

Basic operator and expression

Category, priority and associativity of operator

There are many operators and expressions in C language, which is seldom in the high-level language. It is the rich operator and expression that complete the C language. This is one of main features of C language.

The operators of C language have different priorities. In addition, they have individual associativity. In the expression, the data for operation should not only conform to the priority of operators but also subjected to the associativity so as to confirm the operation direction from left to right or from right to left. This associativity is unavailable for other high-level language, which increases the complexity of C language.

Operator Category

The operators of C language can be classified as following:

1.  Arithmetic operator

It is used for different data operations, including addition (+), subtraction (-), multiplication (*) and division(/) (or modular arithmetic, %), increment (++) and decrement (--).

2.  Relational operator

It is used for comparison operation, including greater than (>), less than (<), equal to (==), be equal or greater than (>=), be equal or less than (<=) and unequal to (! =).

3.  Logical operator

It is used for logical operation, including And (&&), Or (||) and Not (!).

4.  Bit operation operator

The data for operation is taken as binary bit, including bit and (&), bit or (|), bit not (~), bit or (^), left shift (<<) and right shift (>>).

5.  Assignment operator

It is used for assignment operation, including simple assignment (=), composite arithmetic assignment (+=,-=,*=, /=, %=)

and composite bit operation assignment (&=,|=, ^=,>>=,<<=).

6.  Conditional operator

This is a ternary operator for conditional evaluation (?:).

7.  Comma operator

It is used for combining several expressions to one expression (, ).

8.  Pointer operator

It is used for two operations as content-of (*) and address-of (&).

9.  Size-of operator

It is used for size-of operation of data.


10. Special operator

It includes bracket (), subscript [] etc.