The "PEMDAS" mnemonic is helpful in most situations, including this one. Evaluating the expression [MATH]2(3)^2[/MATH] performs the exponentiation first, followed by the multiplication. To put it another way, it is evaluated as [MATH]2(3^2)[/MATH]. Careful positioning of parentheses, and even use of redundant parentheses that are not strictly necessary, can help to eliminate ambiguity and promote correct interpretation in other readers.
PEMDAS does not cover every operation, however. My favorite example is [MATH]-3^2[/MATH]. Is this interpreted as [MATH](-3)^2 = 9[/MATH], or [MATH]-(3^2) = -9[/MATH]? It can be reasoned that it should be interpreted as [MATH]0 - 3^2 = -9[/MATH], as there is an implicit leading zero. However, in applied fields such as computer programming, it can instead be reasoned that the [MATH]-[/MATH] symbol denotes
negation, not subtraction, which is a unary operation and therefore has a higher priority than the binary operation of exponentiation.
Wikipedia
uses the same example and suggests that there is no universal rule in this situation--the context determines its meaning. Once again, parentheses help to circumvent the possibility of misinterpretation in the event the reader doesn't happen to know the intent of the [MATH]-[/MATH] symbol.
As an aside...
In computer lingo, the order of operations is called
operator precedence, which has its foundations in mathematics and is unambiguously defined for all operations (in before someone brings up compound assignments). In most (all?) programming languages, the negation operation has higher priority than multiplication, even in languages (such as C in the link above) that don't have an operator for exponentiation.
Because operator precedence is completely unambiguous, parentheses are only needed when the order of operations needs to be modified. My go-to example (pun intended) for this is the expression
a & b >> c
, which shares the same precedence relationship as the expression
a + b * c
. People have
adamantly argued with me about how they believe it should be written as
a & (b >> c)
to avoid confusion, "in case the reader doesn't know the precedence rules", yet they take no issue with
a + b * c
being written without parentheses, "since the reader should already know that". The way I see it, if you know that multiplication happens before addition, you should also know that right shift happens before bitwise AND. If you
don't know that, you need to review your operator precedence!
Ultimately, those people get the last laugh: gcc
has a warning for those cases "whose precedence people often get confused about". If I want my code to compile without warnings in all cases (enabling all warnings is considered good form), I have to use those redundant, unnecessary, condescending, space-wasting parentheses. *grumble*