I sometimes find this inconvenient when doing bit manipulation (though I can't recall to mind any specific examples right now). I also find it conceptually confusing, since shifts are basically multiplication and division by powers of two.
I see that it can be convenient in C++, when using << to send output to an ostream, but of course that can't be used to explain how the order was originally fixed in C.
The table below lists the C language operators in order of precedence and shows the direction of associativity for each operator. The primary operators have the highest precedence. The comma operator has the lowest precedence.
LOWEST PRECEDENCE The compound logical operators, &&, ||, -a, and -o have low precedence. The order of evaluation of equal-precedence operators is usually left-to-right.
Certain operators have higher precedence than others; for example, the multiplication operator has a higher precedence than the addition operator. For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has a higher precedence than +, so it first gets multiplied with 3*2 and then adds into 7.
Because that's what the authors of the C language decided.
Use parentheses to avoid confusion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With