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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
32 views

Can you tell me the truth about order of evaluation VS precedence VS associativity in C? [duplicate]

i read some time ago about precedence and associativity of operators in C And i thought i have it clear but read some post here on SO and i think im stuck... I read some posts/questions, here is one ...
Cblue X's user avatar
  • 183
0 votes
1 answer
55 views

Why this operation is not following the precedence and associativity table in C? [duplicate]

I was trying to learn about difference between functions and macro with arguments (aka 'macro function' ?) and i got this code: #include <stdio.h> #define mult_m(a) a*a int mult_f(int a){ ...
Cblue X's user avatar
  • 183
-1 votes
0 answers
40 views

Order of evaluation and associativity of ternary operator in C [duplicate]

I know associativity of an operator is a property that determines how operators of the same precedence are grouped in the absence of parentheses And, ternary operators in C are right to left ...
Ajit Kumar's user avatar
0 votes
0 answers
26 views

Why the bracket is not evaluated first in this Java program? [duplicate]

public class Test { public static void main(String [] args) { String text = "GOOD "; text = text + (text = "LUCK "); System.out.println(text); } } ...
Suman Saurabh's user avatar
1 vote
1 answer
48 views

Runtime error: `load of null pointer of type 'char'` when indexing an array

I'm trying to write a trim function, but when I try to use it the compiler is giving me a runtime error or load of null pointer of type 'char' when I try to run this code: // Trim trailing whitespace ...
Debuholden's user avatar
-1 votes
0 answers
66 views

In SQL, what is the precedence of the EXISTS operator? [duplicate]

I have not yet been able to find a table of operator precedence for standard SQL. I have found such tables for some specific dialects, e.g.: https://learn.microsoft.com/en-us/sql/t-sql/language-...
rwallace's user avatar
  • 31.9k
-1 votes
2 answers
110 views

result of this expression is not what i learned

In below code, result is -6. why? ` int x = 5; int y = 3; int result = x++ - (--y + ++x) - y--;` I think at first, inside parenthesis evaluated, then outside of it in left to right order, ...
Guest Man's user avatar
0 votes
2 answers
26 views

I want to know which determines the output like not in this case applies to first condition only or both

x=(not (5==5) and (10<12)) print(x) when executing. not negates the first expression or both? In my opinion "not" should be executed with (5==5) only but my colleague says it will affect ...
sana's user avatar
  • 1
-1 votes
1 answer
65 views

I want to divide any different numbers entered by user through prompt method

The thing is i want is the user to enter the limit of the numbers he or she wants to divide and then i can divide them . Like the user says limit is 4 and then enters numbers like 60/2/3/5 to give 2. ...
 Princessa's user avatar
0 votes
1 answer
41 views

Python Operator Precedence with Shortcut Operator?

I understand that Python follows an operator precedence with the acronym PEMDAS or P-E-MD-AS Now Python happens to use shortcut operators so for example if I were to write x=5 x=x+1 This could be re-...
chilly8063's user avatar
7 votes
1 answer
135 views

VBscript operator precedence inconsistency with VB6

I am running an old VB6.0 program in interpretive mode (i.e. not as a .exe) on Win-7 32-bit. The program accesses VBScript via an MSScriptControl.ScriptControl (as illustrated in the code block below) ...
steveOw's user avatar
  • 1,035
-1 votes
2 answers
104 views

Order of evaluation between logical and assignment operators [duplicate]

I know that the order of evaluation and precedence of operators in C are independent. But I get confused when there are multiple operators that mandates the order of evaluation. For example: a = b &...
Kain3's user avatar
  • 1
-4 votes
1 answer
71 views

Execution of Assigning value and Logical AND and Ternary operator [duplicate]

I am learning JavaScript, and I do not understand what is the execution sequence of 2nd line. Please advise! let envArr; const envName = envArr && envArr[0] ? envArr[0] : "env1";
user3055964's user avatar
6 votes
1 answer
207 views

Example illustrating the unspecified relative evaluation order of # and ## in the C preprocessor

Some commentary about the accepted answer is at the bottom of this question post. Problem statement According to the C standard (C17 draft, 6.10.3.2 ¶2): The order of evaluation of [the] # and ## ...
Lover of Structure's user avatar
-1 votes
2 answers
113 views

What subexpressions does an operator apply to if it has the highest precedence?

int a = 1, b = 2, c = 3; bool z = a >= b || b == c && !b && !!a; cout << z << endl; I would like to know why this code prints 0. I don't know where to start, even ...
rebecca wong's user avatar
-4 votes
1 answer
398 views

What is the precedence and associativity of operators?

What is the precedence and associativity of operators in C++? Who defines operator precedence and associativity, and how does it relate to order of evaluation? explains how those properties emerge ...
Jan Schultke's user avatar
  • 22.4k
-3 votes
3 answers
134 views

What is the operator precedence/order of evaluation in this complex expression, and why is the result -129?

I don't understand in which order actions take place in C++ expressions. For example: Why do we get here -129? Can you explain order of actions? #include <stdio.h> int main() { char a = 60; ...
Yurii Kapusta's user avatar
0 votes
2 answers
90 views

I cannot understand why it work like that

x = 2 y = 2 if x % 2 == 1 & y % 2 == 0: print(x, y) 2 2 I don't understand the result. When there is if x % 2 == 1 & y % 2 == 0:, I think 2 2 cannot be there.
newnewbiiii's user avatar
0 votes
2 answers
85 views

What is the differnce between `void *ptr[N](int)` and `void (*ptr)[N](int)` in c? [duplicate]

Let's say I have void (*ptr[3])(int) and void (*ptr)[3](int) The first one works as expected. But the second one throws an error. I tried both, but could not figure out the problem. The error reads: &...
pushpa's user avatar
  • 31
1 vote
1 answer
154 views

How does a C++ command with two equal signs work?

I found some code in the program I work with: PWSTR myWchar = NULL; WCHAR *p = myWchar = new WCHAR[4]; How would I read a line with two equal signs? How is it computed? A: myWchar = new WCHAR[4]; ...
user3443063's user avatar
  • 1,497
1 vote
1 answer
53 views

Elvis operator and type casting precedence in Groovy

Let's take the following simple expression: ((Double) null ?: 0).getClass() Results: Groovy 3: class java.lang.Double Groovy 4: class java.lang.Integer Does anyone know the reason for the different ...
ferenc.nagy's user avatar
1 vote
2 answers
108 views

C++ change char in string

if i want to change a single char in a string i can do: #include <iostream> #include <string> using namespace std; int main() { string mystring = "Hello"; mystring[0] = 'T'; ...
Bele's user avatar
  • 25
-3 votes
1 answer
124 views

Confusion about the precedence of ` * ` dereference operator & ` . ` dot or member access operator

class Deep { private: int *data; public: int getDataValue() { return *data; } // Constructor Deep(int d) { data = new int; *data = d; } // Deep Copy ...
night_ZAK's user avatar
4 votes
3 answers
62 views

Using multiple compound assignments in a single expression

I am preparing for a Java exam and I am trying to understand operator precedence and compound assignment operators in depth. I played around with a few expressions which use compound assignment during ...
Rauni Lillemets's user avatar
0 votes
0 answers
55 views

I have a question about C Operator Precedence and Associativity. Newbie. Help me [duplicate]

I am a newbie to C programming. Now, I am trying to understand the topic "C Operator Precedence and Associativity". Especially, I would like to pay attention to the order of evaluation with ...
Daniel Bodyak's user avatar
1 vote
1 answer
51 views

PHP : false OR false OR true == false? [duplicate]

I don't understand what's going on here in PHP. I've spent hours on this until I understood that it doen't work normally, or that I dont understand something. Here the few lines : $test = false OR ...
Lomchat's user avatar
  • 19
-3 votes
2 answers
32 views

in c, is there a proper way to explain this (example in post) loop actions order and does it affect different actions as well?

im a mechanical engineering student doing a course in c so my question here is less about actually helping with coding and more about understanding the logic of the actions in the program (since thats ...
Code Bom's user avatar
1 vote
1 answer
64 views

Multiple expressions in single statement

I am trying to understand two situations in C. Situation - 1: int main() { int x = -5, y = 8, z = 2; z = y - (y = x); printf("%d", z); return 0; } It prints 0. Situation - ...
Raj Ishu's user avatar
2 votes
1 answer
41 views

Why does operator precedence works other way with variable assignment in Javascript

I have a code like this. let y = 2; y *= 3+4; The above line is a short hand of y = y*3+4. So as per the precedence level, * should take a precedence. So i am expecting a calculation like this, (2*3)+...
user2613946's user avatar
2 votes
1 answer
51 views

JavaScript Operator Precedence, Assignment, and Increment?

In JavaScript (JS), ++ has higher precedence than += or =. In trying to better understand operator execution order in JS, I'm hoping to see why the following code snippet results in 30 being printed? ...
mishar's user avatar
  • 401
1 vote
2 answers
63 views

Generating random equations with wrong answers ( operator precedence problem )

I am trying to generate a random Equation and an answer to it. Everything works fine, except the answers are being calculated wrong ( without consideration of operator precedence ). I've been trying ...
Loso's user avatar
  • 74
-6 votes
2 answers
59 views

Which line(s) of the following code would give an error:

public static void main (String[] args) { int a=10,b=20; System.out.println(a+++--b);//line 1 System.out.println(a--+++b);//line 2 System.out.println(a++-++b);//line 3 System.out.println(a+++++b);...
Jayveer Mall's user avatar
1 vote
0 answers
37 views

is C# assignment subexpression/evaluation order compiler dependent

Before I ask the question, I do know that this could be easily solved with a couple if statements. I'm just curious about if the logic is sound. I have a bool condition and a bool ...
Dagan Hartmann's user avatar
0 votes
0 answers
20 views

Is this correctly parsed?

Grammar: E -> E + E | E * E | (E) | id Operator Precedences: (plus) has higher precedence than * (multiply) has higher precedence than ( and ) ( and ) have equal precedence Input: id + id * id I ...
Sannidhya sahu's user avatar
0 votes
1 answer
31 views

Python: real order of execution for equalities/inequalities in expressions? [duplicate]

Imagine this "sneaky" python code: >>> 1 == 2 < 3 False According to Python documentation all of the operators in, not in, is, is not, <, <=, >, >=, !=, == have the ...
oBrstisf8o's user avatar
2 votes
0 answers
30 views

Using gradef with complex quantities in Maxima

I'm using gradef to declare the gradients of certain complex variables (that depend on an independent variable, say, t) in terms of other complex variables dependent on the same independent variable. ...
Nidish Narayanaa's user avatar
-1 votes
1 answer
29 views

Combining && with || in an if statement [duplicate]

I want to have a short if statement on one line that checks if condition A is met and then check if condition B is met, where both conditions are specific strings, but condition B has more than one ...
Anton E's user avatar
  • 75
0 votes
0 answers
25 views

How to deal with order of operation with the inputs from the user in Java?

I am currently working on an assignment where I will ask for the user's input of fractions and the operations between these fractions, the user will enter "quit" in order for the program to ...
JoD's user avatar
  • 1
4 votes
1 answer
104 views

Same function but using for it the name %>% causes a different result compared when using the name :=

I am using a function from @Konrad Rudolph but changed its name from %>% to := and get for the same call different results. `%>%` = function (lhs, rhs) { subst = call('substitute', substitute(...
GKi's user avatar
  • 37.9k
0 votes
2 answers
106 views

How does using a relational operator in an algebraic expression work?

I came across a piece of code where <= is used in an algebraic expression in C. int x=2, y=4, z=5, m=10; m+= x * y + z++ <=m+3; printf("%d, %d", m,z); I've never seen the use of a ...
Anuj Khandelwal's user avatar
-1 votes
1 answer
94 views

Bison: Unexpected token error when trying to parse a multiline expression

I'm making a Visual Basic parser with Flex and Bison for a uni assignment. Most of it seems to be working properly except for the parsing of multiline expressions. Here is an example of a bit of code ...
Samuel Bucher's user avatar
1 vote
1 answer
55 views

C# null-conditional/null-coalescing operator precompiler bug or am I just missing something?

I just pushed some bad code that caused an issue in release and wanted to see if anyone could help clarify what's going on here. Below is a (contrived but runnable) program that illustrates the issue ...
Griswald_911's user avatar
-3 votes
1 answer
80 views

Order of execution for functions on either side of the assignment operator

I want to implement a function $input = ['key1', 'value1', 'key2', 'value2']; // $output = ['key1' => 'value1', 'key2' => 'value2']; $output=[]; do { $output[current($input)] = next($input); ...
caijw's user avatar
  • 25
2 votes
1 answer
71 views

Is the comma in Perl associative in all contexts?

Suppose E, F, and G are expressions that don't involve operators of higher precedence than the comma. Are the expressions ((E, F), G) and (E, (F, G)) equivalent in scalar, list, and/or void contexts? ...
fmg's user avatar
  • 825
1 vote
4 answers
138 views

List context and the comma operator in Perl

Having some significant confusion about what it means to "evaluate in list context", specifically related to the comma operator. In the linked perlop doc, it says: In list context, it's just ...
fmg's user avatar
  • 825
1 vote
0 answers
11 views

operator vs () parenthesis in JAVA

int a=5; a+=5+(++a)+(a++); Now the output should be 24 because first the parenthesis will be executed and if this is so then it will be a=a+5+(++a)+(a++)=>a= 7 + 5 + 6 + 6 but the output ...
Aman Maddhesia's user avatar
0 votes
0 answers
22 views

Python operator `in` and `==` precedence and associativity [duplicate]

I noticed strange behaviour with python operator in and == precedence and associativity. Here is a snippet example: b = {} b['foo'] = 'coo' print('foo' in b) # prints True, expected True ...
Christopher Leong's user avatar
0 votes
1 answer
35 views

Java arithmetic increment operator [duplicate]

int a = 6; int b = a + a++; answer is 12 int a = 6; int c = a++ + a; answer is 13 why are the answers for b and c are different ? since postfix has higher a precedence value, then the answer ...
Harry's user avatar
  • 11
1 vote
2 answers
108 views

Haskell - priority of operations

I'm trying to be clear with the precedence rules in Haskell. When I write the line of code "f a b" it will be interpreted (f a) b ie with a left-associative mechanism. But let's imagine that ...
Ftyupl's user avatar
  • 79
0 votes
2 answers
97 views

Is it possible for me to check if the variable will be assigned with a value?

I have a matrix that is a nested linked list. I want to use operator overloading so that I can do matrix(x,y) to access a 'node'. The problem is, how do I check if that int& will be assigned with ...
Not A Good Programmer's user avatar

1
2 3 4 5
37