Operator Precedence: This determines the order in which operators are evaluated in an expression. Operators with higher precedence are evaluated before operators with lower precedence. For example, in the expression 2 + 3 * 4, the multiplication (*) has higher precedence than addition (+), so 3 * 4 is evaluated first, resulting in 12, and then 2 + 12 is evaluated, resulting in 14.
Associativity: When operators have the same precedence, associativity determines the order in which they are evaluated. For example, the + operator is left-associative, so in the expression 2 + 3 + 4, the leftmost + is evaluated first, resulting in 5, and then 5 + 4 is evaluated, resulting in 9.
Program:
Program.c
In this example, the expressions are evaluated according to operator precedence and associativity rules, demonstrating different results based on how the expressions are written.
Resources :
Test Your Knowledge
Choose The
With supporting text below as a natural lead-in to additional content.