0% found this document useful (0 votes)
26 views2 pages

Explain Operator Precedence and Associativity

The document discusses operator precedence and associativity. It provides a chart that lists operators from highest to lowest precedence. It also explains that associativity determines whether operators of the same precedence are grouped from left to right (left associativity) or right to left (right associativity). Understanding operator precedence and associativity is important for writing expressions that evaluate as expected.

Uploaded by

salmangadyali123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

Explain Operator Precedence and Associativity

The document discusses operator precedence and associativity. It provides a chart that lists operators from highest to lowest precedence. It also explains that associativity determines whether operators of the same precedence are grouped from left to right (left associativity) or right to left (right associativity). Understanding operator precedence and associativity is important for writing expressions that evaluate as expected.

Uploaded by

salmangadyali123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Q.15:- Explain Operator precedence and associativity with chart.

**Operator Precedence and Associativity**:

Operator precedence defines the order in which operators are evaluated in an expression,
while associativity determines the direction in which operators are grouped when they
have the same precedence level.

**Operator Precedence Chart**:

Highest Precedence:

1. () - Parentheses

2. [] - Array subscript

3. -> - Member access through pointer

4. . - Member access

5. ++, -- - Postfix increment and decrement

6. +, - - Unary plus and minus

7. !, ~ - Logical NOT, Bitwise NOT

8. *, /, % - Multiplication, Division, Modulus

9. +, - - Addition, Subtraction

10. <<, >> - Bitwise left shift, Bitwise right shift

11. <, <=, >, >= - Relational operators

12. ==, != - Equality operators

13. & - Bitwise AND

14. ^ - Bitwise XOR

15. | - Bitwise OR

16. && - Logical AND

17. || - Logical OR

18. ?: - Ternary conditional


19. = - Assignment

20. +=, -=, *=, /= - Compound assignment

Lowest Precedence:

**Associativity**:

- **Left Associativity**: Operators with left associativity are grouped from left to right. For
example, the `+` operator has left associativity, so `a + b + c` is evaluated as `(a + b) + c`.

- **Right Associativity**: Operators with right associativity are grouped from right to left.
For example, the `=` operator has right associativity, so `a = b = c` is evaluated as `a = (b =
c)`.

Understanding operator precedence and associativity is essential for writing expressions


that produce the expected results. It helps clarify the order of operations and grouping of
operands in complex expressions.

You might also like