Operator precedence determines the grouping of terms in an expression, which affects how an expression is evaluated. Certain operators take higher precendence over others; for example, the multiplication operator has higher precedence than the addition operator.
For example :
int x = 4+3*2;
Console.WriteLine(x);
// outputs 10
The program evaluates 3*2 first and then adds the result to 4.
As in mathematics using parentheses alters operator precedence.
int x = (4+3)*2;
Console.WriteLine(x);
// outputs 14
No comments:
Post a Comment