edited by
2,264 views
1 votes
1 votes

State True/False: "If two operators in an expression have equal precedence but different associativity then order of their evaluation is compiler dependent."

Considering my adaptation to this question: 
if * and ^(exponentiation) has same precedence

if *  associate from right to left and ^ associates from left to right,   then what will be the result of 2*2^3*4 ? 

edited by

1 Answer

5 votes
5 votes

Answer is false. But the question is bad because both precedence and associativity do not determine the evaluation order in languages like C/C++ where as they do in many other languages.

Example: a + b + c;

Here associativity is left to right (assumed) and hence (a+b) happens first and then + c.

But consider (a + b) + (c + d) + (e+d);

Here (a+b) or (c+d) or (e+d) can happen first.

For the question being adapted, that is never possible. Because all operators having same precedence must have same associativity - because that is the purpose of associativity. See here for example the precedence table in C:

http://ee.hawaii.edu/~tep/EE160/Book/chap5/subsection2.1.4.1.html
 

edited by

Related questions

3 votes
3 votes
5 answers
1
arpit.bagri asked Aug 6, 2023
1,042 views
Why is the output of the below program 36? int main(){ int a = 1; int b = ++a * ++a * ++a; printf("%d", b ); ​​​​ return 0; }
0 votes
0 votes
1 answer
4
Chhotu asked Nov 20, 2017
2,226 views
Hi,Is there any smart way to learn operator precedence table ? (means can we form some kind of logical connection instead of mugging entire table.) If some good reference...