The priority of operators in C programming

 The priority of operators in C programming

In this chapter you will learn about the order of operators. Operators in C program work in the order of pre-order.
Operator precedence indicates the order in which an operator can operate before and after any operator. Associativity operators indicate the direction of operators. It may be left to right or right to left.

Let's try to understand the operator precedence with the following example:

int count = 20 + 20 * 10;
Here the value of the count variable is 220 because
count = multiplication operator (20 * 10) is evaluated before + yoga operator

In C programming, precedence and associativity are presented in the following table:

Category Operator Associity
Postfix                            () [] ->. ++ - -                                                                        Left to right
Unary                             + -! ~ ++ - - (type) * & sizeof                                               right to left
Multiplicative                * /%                                                                                       left to right
Additive                         + -                                                                                          Left to Right
Shift                               << >>                                                                                     Left to Right
Relational                      <<=>> =                                                                             From left to right
Equality                         ==! =                                                                                      Left to right
Bitwise AND & Left to Right
Bitwise XOR ^ Left to Right
Bitwise OR | Left to Right
Logical AND && Left to Right
Logical OR || Left to Right
Conditional?: Right to left
Assignment = + = - = * = / =% = >> = << = & = ^ = | = Right to Left
Comma, left to right

Post a Comment

0 Comments