Results 1 to 4 of 4

Thread: Why does operator precedence matter?

  1. #1
    .NET Framework
    .NET 4.5
    Join Date
    Jan 2017
    Location
    United Kingdom
    Posts
    75
    Rep Power
    25

    Why does operator precedence matter?

    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

  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Posts
    1,933
    Rep Power
    149
    Quote Originally Posted by VitzzViperzz View Post
    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:
    Code:
    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.

  3. #3
    .NET Framework
    .NET 4.5
    Join Date
    Jan 2017
    Location
    United Kingdom
    Posts
    75
    Rep Power
    25
    Thanks for clearing that up. I did kind of understand it, but I don't think I asked the question properly.

  4. #4
    .NET Framework
    .NET 2.0
    Join Date
    Oct 2018
    Location
    India
    Posts
    1
    Rep Power
    0
    Operator precedence determines which operator is performed first in an expression with more than one operators with different precedence.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •