Questions tagged [operator-precedence]
Operator Precedence refers to the rules governing the order in which operators are evaluated within an expression or statement in a programming language. Distinct from [order-of-execution] which covers the sequencing of execution events in a software system.
operator-precedence
1,835
questions
1
vote
1
answer
104
views
Can't understand this C syntax. Designated initialization of an array of structs?
Trying to learn the nuances of C, though I was doing well until I found this:
#define SOKOL_IMPL
#define SOKOL_GLES3
#include "sokol_gfx.h"
#include "sokol_log.h"
#include "...
-5
votes
1
answer
64
views
Comparison Operators result in Python
Why in Python print(bool(7>8)==False==True) results False, logically it should be True?
as bool(7>8) is False, therefore
False==False==True -> True==True -> True (NOT False)
as the ...
1
vote
0
answers
25
views
is.na gives unexpected result when used after magrittr pipe %>% [duplicate]
I'm using == to compare two character vectors, one of which contains NA elements. I then want to pipe the logical output of == to is.na using the magrittr pipe operator %>%. When I do this directly ...
-3
votes
4
answers
139
views
Why pointer precedence in while loop is working differently? [closed]
*s++ evalutes right to left .
while loop inside main is evaluting as right to left but while loop outside main is working as it has precedence left to rigth why???
int main(void) {
char* s = "...
0
votes
0
answers
44
views
Why does the order of addition/subtraction sometimes matter in MATLAB? [duplicate]
I have a simple function, a - b + c, whose value depends on the order of addition/subtraction:
clear; clc;
a = -1.0;
b = 0.9;
c = 0.9;
d = a - b + c;
e = a - (b - c);
f = (a - b) + c;
g = a + c - b;...
2
votes
2
answers
121
views
Operator precedence of `EXISTS`
In Postgres, does the EXISTS operator have the highest precedence of all? For example:
SELECT 1 + EXISTS (SELECT 1)::int;
It seems to be missing from the manual page. Though the highest one is ::, ...
-1
votes
1
answer
46
views
How to explain null-coalescing expression precedence evaluation with some operators?
The following code works fine. What is the logic behind the addition + being evaluated after the null-coalescing ??? How's that possible? Where is the doc explaining that?
int? tNullable = 2;
...
0
votes
1
answer
33
views
How can I boost the precedence of an Antlr4 parser branch?
I created the following grammar:
grammar Test;
COMMA: ',';
OPEN: '(';
CLOSE: ')';
ATOM: [0-9a-zA-Z_]+;
SPACE: [ \r\n\t]+ -> skip;
start: expr EOF;
expr
: ATOM ...
0
votes
4
answers
133
views
Does the && (logical AND) operator have a higher precedence than || (logical OR) operator in Java?
From my previous knowledge the (logical AND) has a higher precedence than the (logical OR), so for example in the following line of Java code boolExp2 will be compared with boolExp3 before comparing ...
2
votes
0
answers
62
views
Operator precedence in Java with assignment [duplicate]
Can anyone help me understand the logic behind the following results?
Case 1.
int x,a = 100;
x = a + (a=6);
System.out.println(x); //prints 106
Case 2.
int x,a =100;
x = (a=6) + a;
System.out....
0
votes
0
answers
30
views
I don't understand how the final values of 2 variables are calculated after an addition of a pre-increment and post-increment [duplicate]
#include <stdio.h>
int main()
{
int i = 0;
int j = 0;
j = i++ + ++i;
printf("%d %d", i, j);
return 0;
}
After compilation and run, the output is i = 2 and j = 2
I don'...
0
votes
1
answer
166
views
Why does the PHP null-coalescing operator (??) behave irrationally with == and ===? [duplicate]
var_dump(3 ?? null);
var_dump(3 ?? null === null);
var_dump(3 === null);
var_dump(3 ?? 1 > 2);
var_dump(null ?? 1 > 2);
What do you consider the outputs to be?
So the question is really this:
...
1
vote
5
answers
204
views
How is pointer ++*ptr++ evaluated
So I'm quite confused as to how the post-increment is not evaluated first. (According to precedence post-increment comes first.) Can someone please explain this?
Consider the code given below:
int ...
0
votes
0
answers
61
views
How do I implement precedence climbing correctly in rust
I am writing a compiler in rust and I am stuck trying to implement a precedence climbing algorithm.
The structure of the parse tree generates correctly but the infix operator in the tree are wrong.
...
2
votes
0
answers
107
views
How does Python parse `7 in x == True`? [duplicate]
I saw a question on es.stackoverflow.com in which the author tried to explicitly compare the result of a boolean expression to True.
if nota in lista1 == True:
...
I wasn't sure of the operator ...