All Questions
Tagged with precedence or operator-precedence
1,859 questions
Advice
1 vote
7 replies
154 views
Priority of Java's conditional ? : operator
The conditional ? : operator in Java is right-associative. So the expression a<b ? c<d ? 1 : 2 : 3 ; is evaluated as a<b ? (c<d ? 1 : 2) : 3 ; Does this mean that the expression (c<d ?...
1 vote
1 answer
223 views
Unexpected evaluation of expression with incrementation, decrementation, multiplication, concatenation, addition-assignment, multiplication-assignment [duplicate]
I've been struggling to understand why this returns 252448 instead of 251248. <?php $a = 4; echo ++$a * $a++ . $a += $a . $a *= 4; ?> My thinking is: ++$a * $a++ gives 25 (5*5), after that we ...
58 votes
1 answer
5k views
Why do bit operators have such low precedence in C and C++?
In C and C++, the expression some_num & 0xABCD == 5 will effectively evaluate as some_num & (0xABCD == 5). This is unlike all of the standard arithmetic operators, as they have higher ...
4 votes
2 answers
258 views
Shift "<<" and bitwise "&" operators precedence issue. Why it doesn't compile?
This code doesn't compile. It seems like the compiler (VS) is interpreting the expression as: (std::cout << ul1) & (ul2 << std::endl) #include <iostream> int main() { ...
1 vote
1 answer
75 views
What is the precedence of parameter binding?
I am a PowerShell novice. Suppose that I wish to call Get-Service -Name winrm, netlogon Due to parameter binding, this will be parsed as if we typed @("winrm", "netlogon") rather ...
1 vote
0 answers
145 views
difference between bottom-up parser Precedence climbing and top-down parser Pratt parsing
I encountered with this problem while reading about Precedence climbing and Pratt parsing. This may be duplicate with this QA but that doesn't say much about Precedence climbing and Pratt parsing. The ...
1 vote
1 answer
87 views
How do conditional expressions group from right to left?
I checked python operator precedence (This one grammar is more detailed and more appropriate for the actual Python implementation) Operators in the same box group left to right (except for ...
-1 votes
1 answer
115 views
Evaluation order in java [duplicate]
Why am I getting the output as 15 and not 10 for the following code? class Main { public static void main(String[] ARGS){ int x = 10; x += (x=5); System.out.println(x); ...
6 votes
2 answers
252 views
What's the difference between *p++ and *p += 1 in C?
I have just started learning about pointers in C and was using a pointer p to iterate through the elements of an array. My goal was to increment every element by one, but after applying the increment ...
0 votes
1 answer
40 views
Python evaluation of expression [duplicate]
Python yields different answers >>> 0 < 0 == 0 False >>> (0 < 0) == 0 True >>> 0 < (0 == 0) True is this a bug? Python 3.11.10 (main, Sep 7 2024, 18:35:41) [GCC ...
0 votes
0 answers
48 views
does variable assignment escape order of operations in c? [duplicate]
My understanding is that the order of operations happens left to right in c, unless there's an operation that takes precedent (like multiplication happens before addition). int i = 3 * 2 + 4; //i == ...
1 vote
2 answers
94 views
What is the difference between order of precedence and order of evaluation in C? [duplicate]
I have a specific example in mind. x = a +++ b; This is evaluated as a++ not ++b. But I don't understand if this is due to order of precedence of postfix being higher than prefix, or due to order of ...
1 vote
2 answers
83 views
Why assignment operator and its 'variants' doesnt show up in the 'Precedence table' of python?
I was searching in the python documentation in order to get the 'Precedence table' of the operators in python, here it is (at least for python 3.12.7), Section 6.17: https://docs.python.org/3.12/...
0 votes
2 answers
88 views
i*=j ==x and i=i*j ==x behaving differently in C
I have these two code snippets that are acting differently: int i=2,j=3; if (j*=i == 2){ printf("yes, i= %d, j= %d",i,j); } else { printf("no, i= %d, j= %d",i,j); } int i=...
4 votes
3 answers
169 views
How does operator precedence affect the evaluation of $x = false && print 'printed' || true;? [duplicate]
I'm trying to understand why this expression: $x = false && print 'printed' || true; results in $x being false instead of true. I know that && has higher precedence than ||, but I'm ...