# Why does operator precedence matter?

#### VitzzViperzz

##### Well-known member
I was just going through a book and I saw that there was a figure that showed operator precedence. With some research I found out that it is all about the priority of the expressions when it comes to debugging. But why would this be any use to us when making an application?

I know how they would use it but I cannot understand WHY they would use it while making an application?

Looking forward to a response,
Thanks

With some research I found out that it is all about the priority of the expressions when it comes to debugging.

It's got nothing to do with debugging specifically. Operator precedence defines the order in which subexpressions will be evaluated and therefore what the result of an expression will be. If you've done maths at school then there's no reason to be asking this question because it works EXACTLY the same way as it does in algebra. This:
C#:
``2 + 3 * 4``
might be expected to evaluate to 20 by someone with no knowledge of operator precedence because they might perform the addition before the multiplication but those of us who have done primary school maths know that it actually evaluates to 14 because the multiplication is performed first. That is exactly how it works in programming too. Mathematical operators have the same precedence in C# as they do in primary school maths class and then you have to consider Boolean and other operators too but the principle is exactly the same.

Thanks for clearing that up. I did kind of understand it, but I don't think I asked the question properly.

Operator precedence determines which operator is performed first in an expression with more than one operators with different precedence.

Replies
7
Views
628
Replies
3
Views
304
Replies
5
Views
529
Replies
13
Views
493
Replies
27
Views
1K