answersLogoWhite

0


Best Answer

Calculate y in the following equation: y = 2 + 3 x 4 What answer did you get? Did you get 20? If you did, you messed up. You should have gotten 14. If you got 20, you did the operations in the order in which they appear, from left to right, which is a mistake. You added 2 and 3, to get 5, and then you multiplied by 4, to get 20. But you should have multiplied 3 by 4, first, to get 12, and added that product to 2, to get 14. That's because multiplication (and division) take precedent over addition (and subtraction). Now, try this: y = (2 + 3) x 4 Did you get 20? If so, you got the right answer. Do you know why?

User Avatar

Wiki User

16y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

A characteristic of operators that indicates when they will be evaluated when they appear in complexexpressions. Operators with high precedence are evaluated before operators with low precedence. For example, the multiplication operator has higher preference than the addition operator , so the expression234 equals 14, not 20. You can override precedence rules by surrounding parts of an expression

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What do you mean by operator precedence and associativity?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Associativity has no role to play unless the precedence of operator isHow much memory is required to store a value of type double?

yes


How do you evaluate an expression in hierarchy of operations?

Expressions are evaluated according to the language grammar. Operator precedence and associativity are derived from the grammar in order to aid our understanding, however the order of evaluation is independent of both because the C language standard does not specify operator precedence. The general arithmetic rules of precedence hold for most expressions such that parenthesised operations take precedence over orders followed by multiplication/division operations and finally addition/subtraction operations (as per the PODMAS acronym). Many of the more complex expressions we encounter can generally be evaluated according to the operator precedence table, which includes the associativity, such that operations with higher precedence are bound more tightly (as if with parenthesis) than those with lower precedence.


How many operators in c?

Quite a few. Some of them are: , () [] & * . -> + ++ += - -- -= * / % *= /= %= ! == <= >= < > != << >> >>= <<= & | ^ ~ &&


How can you compare precedence of operators in programming of conversion of infix to postfix?

Each operator has a certain precedence level, usually some numeric value. As you parse the expression, you compare the precedence of each operator with the precedence of the last operator, and you either generate code or you push the operator and its operand(s) on two stacks.


What is the C plus plus expression and operator precedence?

Precedence is determined by operators only. Every operator has a precedence in the range 1 through 17, where 1 has the highest precedence. All precedences have left-to-right associativity except 3 and 15 which are right-to-left. Precedence 1: scope-resolution operator Precedence 2: postfix increment/decrement, function-style type cast, function call, array subscripting and selection by reference or pointer. Precedence 3: prefix increment/decrement, unary plus/minus, logical and bitwise NOT, C-style cast, dereferencing, address-of, sizeof, new/new [] and delete/delete []. Precedence 4: pointer to member. Precedence 5: multiplication, division and modulo. Precedence 6: addition and substraction. Precedence 7: bitwise left/right shift. Precedence 8: relational operators (<, <=, > and >=). Precedence 9: equal/not equal operators (= and !=) Precedence 10: bitwise AND Precedence 11: bitwise XOR Precedence 12: bitwise OR Precedence 13: logical AND Precedence 14: llogical OR Precedence 15: ternary conditional, assignment and compound assignment. Precedence 16: throw Precedence 17: comma

Related questions

Associativity has no role to play unless the precedence of operator isHow much memory is required to store a value of type double?

yes


How do you evaluate an expression in hierarchy of operations?

Expressions are evaluated according to the language grammar. Operator precedence and associativity are derived from the grammar in order to aid our understanding, however the order of evaluation is independent of both because the C language standard does not specify operator precedence. The general arithmetic rules of precedence hold for most expressions such that parenthesised operations take precedence over orders followed by multiplication/division operations and finally addition/subtraction operations (as per the PODMAS acronym). Many of the more complex expressions we encounter can generally be evaluated according to the operator precedence table, which includes the associativity, such that operations with higher precedence are bound more tightly (as if with parenthesis) than those with lower precedence.


How many operators in c?

Quite a few. Some of them are: , () [] & * . -> + ++ += - -- -= * / % *= /= %= ! == <= >= < > != << >> >>= <<= & | ^ ~ &&


What are the differences between precedence and associativity?

Precedence rules specify priority of operators (which operators will be evaluated first, e.g. multiplication has higher precedence than addition, PEMDAS).The associativity rules tell how the operators of same precedence are grouped. Arithmetic operators are left-associative, but the assignment is right associative (e.g. a = b = c will be evaluated as b = c, a = b).


Which direction are java operators evaluated from?

It depends on the operator. Some have right-to-left associativity, some are left-to-right, some have no associativity.


How can you compare precedence of operators in programming of conversion of infix to postfix?

Each operator has a certain precedence level, usually some numeric value. As you parse the expression, you compare the precedence of each operator with the precedence of the last operator, and you either generate code or you push the operator and its operand(s) on two stacks.


What is the C plus plus expression and operator precedence?

Precedence is determined by operators only. Every operator has a precedence in the range 1 through 17, where 1 has the highest precedence. All precedences have left-to-right associativity except 3 and 15 which are right-to-left. Precedence 1: scope-resolution operator Precedence 2: postfix increment/decrement, function-style type cast, function call, array subscripting and selection by reference or pointer. Precedence 3: prefix increment/decrement, unary plus/minus, logical and bitwise NOT, C-style cast, dereferencing, address-of, sizeof, new/new [] and delete/delete []. Precedence 4: pointer to member. Precedence 5: multiplication, division and modulo. Precedence 6: addition and substraction. Precedence 7: bitwise left/right shift. Precedence 8: relational operators (<, <=, > and >=). Precedence 9: equal/not equal operators (= and !=) Precedence 10: bitwise AND Precedence 11: bitwise XOR Precedence 12: bitwise OR Precedence 13: logical AND Precedence 14: llogical OR Precedence 15: ternary conditional, assignment and compound assignment. Precedence 16: throw Precedence 17: comma


What is precedence between relational operator and arithmetic operator?

Arithmetic operators (+, -, *, /, % ) have greater precedence over relational operators (<, >, <=, >=, ==, !=) in C language.


Logical or operator can be compared to what in terms of precedence?

The logical OR operator can be compared to ____ in terms of precedence.


How do you Know if a grammar is an operator precedence grammar?

The grammar is said to be operator precedence grammar, if its right hand side of its production should not have the Empty production or two non-terminal should not be adjacent to each other, then we call it as operator precedence grammar The grammar is said to be operator precedence grammar, if its right hand side of its production should not have the Empty production or two non-terminal should not be adjacent to each other, then we call it as operator precedence grammar


What is the order of precedence with regard to the operator used in embedded C program?

Operator precedence in embedded C is exactly the same as in standard C.


What pair of brackets can be used to override the precedence of the operators in Excel?

Parentheses or round brackets ( and ) override operator precedence.