Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Operator associativity
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Property determining how equal-precedence operators are grouped}}{{for|the mathematical concept of associativity|Associative property}} In [[programming language theory]], the '''associativity''' of an [[Operator (programming)|operator]] is a property that determines how operators of the same [[order of operations|precedence]] are grouped in the absence of [[Bracket (mathematics)|parentheses]]. If an [[operand]] is both preceded and followed by operators (for example, <code>^ 3 ^</code>), and those operators have equal precedence, then the operand may be used as input to two different operations (i.e. the two operations indicated by the two operators). The choice of which operations to apply the operand to, is determined by the '''associativity''' of the operators. Operators may be '''associative''' (meaning the operations can be grouped arbitrarily), '''left-associative''' (meaning the operations are grouped from the left), '''right-associative''' (meaning the operations are grouped from the right) or '''non-associative''' (meaning operations cannot be chained, often because the output type is incompatible with the input types). The associativity and precedence of an operator is a part of the definition of the programming language; different programming languages may have different associativity and precedence for the same type of operator. {{anchor|rightAssociative}}Consider the expression <code>a ~ b ~ c</code>. If the operator <code>~</code> has left associativity, this expression would be interpreted as <code>(a ~ b) ~ c</code>. If the operator has right associativity, the expression would be interpreted as <code>a ~ (b ~ c)</code>. If the operator is non-associative, the expression might be a [[syntax error]], or it might have some special meaning. Some mathematical operators have inherent associativity. For example, subtraction and division, as used in conventional math notation, are inherently left-associative. Addition and multiplication, by contrast, are both left and right associative. (e.g. <code>(a * b) * c = a * (b * c)</code>). Many programming language manuals provide a table of operator precedence and associativity; see, for example, [[Operators in C and C++#Operator precedence|the table for C and C++]]. The concept of notational associativity described here is related to, but different from, the mathematical [[associativity]]. An operation that is mathematically associative, by definition requires no notational associativity. (For example, addition has the associative property, therefore it does not have to be either left associative or right associative.) An operation that is not mathematically associative, however, must be notationally left-, right-, or non-associative. (For example, subtraction does not have the associative property, therefore it must have notational associativity.)
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)