Questions tagged [operator-precedence]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
5
votes
2answers
610 views

What is the logic in the order of operator precedence? [closed]

Absolutely academic context question- I found countless articles listing the order of operator precedence in all languages, but what is the logical reasoning behind that specific order? For clarity ...
-1
votes
2answers
1k views

Should I use parenthesis around every operators?

The facts This is a very similar question to this one, but here I am talking about a more general case the MISRA-C3 Rule 5.0.2 or the SEI CERT C EXP00-C rule (more permissive). Within MISRA-C3 I ...
0
votes
2answers
178 views

Operators precedence

I have a code snippet in Java: int y = ++x * 5 / x-- + --x; So my confusion was since x--(postfix) has higher precedence than ++x(prefix) operator so x-- should be executed first then ++x.But a ...
-3
votes
2answers
148 views

Operators precedence in java (unary plus and addition) [closed]

I'm having trouble in figuring out why the output for theses two lines is different .. public static void main(String[] args) { System.out.println("6.0+1="+6.0+1); System.out.println("6.0+1="+(...
3
votes
1answer
1k views

Shunting-yard algorithm and unary minus

I am attempting to implement a shunting-yard algorithm for a calculator following the rules laid out in https://en.wikipedia.org/wiki/Shunting-yard_algorithm . When programming the unary minus, ...
4
votes
3answers
1k views

Is order of arguments in an arithmetic expression important to achieve as most exact result as possible (speed is not necessary)?

Actually, in this question I do not ask about particular language or architecture, however I understand there might be some differences. In physics / engineering it is usually better to handle ...
0
votes
3answers
152 views

Proper way to interpret this dereference operation?

I've seen this example in a text book and am a little confused how to interpret the operator precedence rules. Given this struct: typedef struct { char *data; size_t start, end; } ...
9
votes
3answers
4k views

Precedence of function in Shunting-yard algorithm

I am working through the Shunting-yard algorithm, as described by wikipedia. The description of the algorithm when dealing with operators is as follows: If the token is an operator, o1, then: ...
1
vote
1answer
134 views

The difference between (-(a*b)) and ((-a)*b)

One of our teachers said that there is just one example that there is a difference between (-(a*b)) and ((-a)*b). He said by using two's complement you can find one. I am trying to find this example. ...
0
votes
1answer
270 views

Order of Operations Annoyance [duplicate]

In most programming languages (C#, JavaScript, Java) the order of operations precedence has that equality comparison come BEFORE bitwise comparisons. This means that if you have a bit operation and ...
1
vote
2answers
782 views

Should ** bind more tightly than !, ~?

Designing a programming language, I'm including the ** exponentiation operator. In Fortran and Python, the two languages I know of which have this operator, it binds more tightly than unary minus, ...
99
votes
14answers
53k views

Should I use parentheses in logical statements even where not necessary?

Let's say I have a boolean condition a AND b OR c AND d and I'm using a language where AND has a higher order of operation precedent than OR. I could write this line of code: If (a AND b) OR (c AND d)...
3
votes
1answer
172 views

Evaluation order of the expressions

The C Programming Language by K & R states that C, like most languages, does not specify the order in which operands of an operator are evaluated. (The exceptions are &&,||,?: and ','). ...
63
votes
2answers
6k views

Why do bitwise operators have lower priority than comparisons?

Could someone explain the rationale, why in a bunch of most popular languages (see note below) comparison operators (==, !=, <, >, <=, >=) have higher priority than bitwise operators (&, |, ^...