Search code examples
programming-languageslogical-operators

mathematical VS logical operators precedence


why is it that in most programming languages the mathematical operators precedence is different from the logical operators precedence.

meaning: why is x / y * z evaluates to ( x / y ) * z so that / has the same precedence as * but in logical operators x || y && z would evaluate to x || ( y && z ) So, is there a logical reason for this distinction ( some hardware reason, optimization technique) or is it just the way programming language creators decided to make them??


Solution

  • It's not about programming. Ever worked with boolean algebra? AND has precedence over OR there too, and boolean algebra is from the 17th century (though I don't know when this convention came to be). The two are also written as * and +, which gives a clue in that regard (but can confuse in others).

    Programming language designers just carried these precedence rules over, just like they carried over the precedence of arithmetic operators.