Computer Science, asked by angelsaini1084, 1 month ago

operator is executed before + operator.​

Answers

Answered by kajalkaur982004
3

The first and most important rule is called operator precedence. Operators in an expression that have higher precedence are executed before operators with lower precedence. ... Right-associative operators of the same precedence are evaluated in order from right to left. For example, assignment is right-associative.

Answered by Anonymous
2

\huge \color{purple} \mathcal{ \colorbox{orange}{\colorbox{white}{♣Answer}}}

In an expression that contains multiple operators, Java uses a number of rules to decide the order in which the operators are evaluated. The first and most important rule is called operator precedence. Operators in an expression that have higher precedence are executed before operators with lower precedence. For example, multiplication has a higher precedence than addition. In the expression 2+3*4, the multiplication is done before the addition, producing a result of 14.

If consecutive operators in an expression have the same precedence, a rule called associativity is used to decide the order in which those operators are evaluated. An operator can be left-associative, right-associative, or non-associative:

  • Left-associative operators of the same precedence are evaluated in order from left to right. For example, addition and subtraction have the same precedence and they are left-associative. In the expression 10-4+2, the subtraction is done first because it is to the left of the addition, producing a value of 8.

  • Right-associative operators of the same precedence are evaluated in order from right to left. For example, assignment is right-associative. Consider the following còde fragment:

  • int a = 3;
  • int b = 4;
  • a = b = 5;

  • After the còde has been evaluated, both a and b contain 5 because the assignments are evaluated from right to left.

  • A non-associative operator cannot be combined with other operators of the same precedence.

  • Table 4-2 shows the precedence and asßociativity of all the operators in Java.[7]

[7] Although the precedence of operators in Java is similar to that in C++, there are some differences. For example, new has a higher precedence in Java than it does in C++. Another difference is that the ++ and - - operators are effectively non-asßociative in Java.

Similar questions