We use cookies.This website uses essential cookies to operate core features. With your consent, we also use analytics cookies to understand traffic and improve the service. For more details, see our .
Was this tool helpful to use?
Your feedback helps us make it better
Free online quick reference cheat sheet for Objective-C operator precedence and associativity. Easily check execution order and evaluation rules.
A curated syntax reference, not a compiler or example validator. Local group numbers do not replace version-specific grammar, typing or evaluation rules. Examples keep their original code and literals. Reference
[]Postfix & AccessLeft-to-right用于数组或集合下标访问;在 Objective-C 中方括号也用于向对象发送消息。
items[index] / [view setNeedsLayout]()Postfix & AccessLeft-to-right改变表达式求值顺序,或调用 C 函数、Block、方法返回的函数指针。
(a + b) * c / NSLog(@"%@", text).Postfix & AccessLeft-to-right访问结构体成员,也常用于 Objective-C 属性的点语法。
point.x / object.title->Postfix & AccessLeft-to-right通过结构体指针访问成员。
node->nexta++Postfix & AccessLeft-to-right先取得原值,再将变量加 1。
index++a--Postfix & AccessLeft-to-right先取得原值,再将变量减 1。
index--+aUnaryRight-to-left保留数值本身,通常用于明确表达正值。
+count-aUnaryRight-to-left返回操作数的相反数。
-offset++aUnaryRight-to-left先将变量加 1,再取得新值。
++index--aUnaryRight-to-left先将变量减 1,再取得新值。
--index(type)UnaryRight-to-left把表达式显式转换为指定 C 或 Objective-C 指针类型。
(UIView *)sender*aUnaryRight-to-left读取指针指向位置的值。
*buffer&aUnaryRight-to-left取得变量、结构体成员或对象指针变量的地址。
&error!UnaryRight-to-left对布尔或条件表达式取反。
!isHidden~UnaryRight-to-left对整数每一位取反。
~masksizeofUnaryRight-to-left返回类型或表达式占用的字节数,结果类型为 size_t。
sizeof(CGPoint)*MultiplicativeLeft-to-right两个数值相乘。
width * scale/MultiplicativeLeft-to-right执行数值除法;整数除法会截断小数部分。
total / count%MultiplicativeLeft-to-right返回整数相除后的余数。
index % 2+AdditiveLeft-to-right数值相加,也可用于指针与整数的偏移。
x + y-AdditiveLeft-to-right数值相减,或两个指针相减得到元素距离。
max - min<<ShiftLeft-to-right将整数二进制位向左移动指定数量。
1 << bit>>ShiftLeft-to-right将整数二进制位向右移动指定数量。
flags >> 1>RelationalLeft-to-right判断左操作数是否大于右操作数。
count > limit>=RelationalLeft-to-right判断左操作数是否大于或等于右操作数。
count >= minimum<RelationalLeft-to-right判断左操作数是否小于右操作数。
index < total<=RelationalLeft-to-right判断左操作数是否小于或等于右操作数。
index <= lastIndex==EqualityLeft-to-right比较两个值是否相等;对象内容比较通常应使用 isEqual: 等方法。
status == 200!=EqualityLeft-to-right比较两个值是否不相等。
object != nil&BitwiseLeft-to-right对两个整数逐位执行与运算。
options & NSCaseInsensitiveSearch^BitwiseLeft-to-right对两个整数逐位执行异或运算。
mask ^ flag|BitwiseLeft-to-right对两个整数逐位执行或运算,常用于组合选项位。
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight&&LogicalLeft-to-right短路与;左侧为假时不再计算右侧表达式。
view != nil && !view.hidden||LogicalLeft-to-right短路或;左侧为真时不再计算右侧表达式。
cached || [self reloadData]?:ConditionalRight-to-left根据条件在两个表达式之间选择一个结果。
title.length ? title : @"Untitled"=AssignmentRight-to-left把右侧表达式结果写入左侧变量或属性。
self.title = title/=AssignmentRight-to-left将左值除以右侧表达式后再赋回左值。
scale /= 2*=AssignmentRight-to-left将左值乘以右侧表达式后再赋回左值。
height *= ratio%=AssignmentRight-to-left将左值取余后再赋回左值。
index %= count+=AssignmentRight-to-left将右侧表达式加到左值上并赋回。
x += delta-=AssignmentRight-to-left从左值中减去右侧表达式并赋回。
remaining -= used<<=AssignmentRight-to-left左移指定数量后赋回左值。
flags <<= 1>>=AssignmentRight-to-left右移指定数量后赋回左值。
flags >>= 1&=AssignmentRight-to-left执行按位与后赋回左值。
options &= allowed^=AssignmentRight-to-left执行按位异或后赋回左值。
mask ^= flag|=AssignmentRight-to-left执行按位或后赋回左值。
options |= UIViewAnimationOptionCurveEaseInOut,CommaLeft-to-right从左到右依次求值多个表达式,整个表达式结果为最后一个表达式的值。
i++, j--Overview
Understand what the tool solves, how it works, and the boundaries of its data.
This page is a lookup table for common C-family expression operators, with Objective-C-flavored examples. Each result shows a symbol, category, short description, associativity, and code example. The filterable groups cover primary and postfix forms, unary operators, arithmetic, shifts, comparisons, bitwise and logical operators, the conditional operator, assignments, and the comma operator. Search can match a symbol, name, description, example, or group number; category and associativity filters can narrow the list.
The displayed numbers run from 1 to 15, and a smaller number means tighter binding. They are convenient labels used by the page, not numbered levels prescribed by C or Objective-C. The C language defines expression grouping through grammar. Objective-C adds its own expression forms, such as bracketed message expressions and property dot syntax, so use the table as a quick guide to the listed entries rather than a complete language grammar.
Precedence: determines how operators at different levels group. 2 + 3 * 4 groups as 2 + (3 * 4).
Associativity: groups a chain of operators at the same level. a - b - c groups as (a - b) - c; a = b = c groups as a = (b = c).
Grouping is not a general promise about the runtime order in which operands or function calls execute. The C standard's expression rules distinguish grammatical grouping from evaluation and sequencing rules.
Guide
Follow the workflow and verify inputs and outputs with practical examples.
Enter a token such as &&, ?:, or ++, or search a name, example word, or displayed number. Search checks the listed row text and example, then shows matching entries grouped by their displayed level.
Choose a category such as Bitwise or Assignment, or select left-to-right or right-to-left associativity. Leave a filter at All when you want to combine it with keyword search without excluding other groups.
Compare the row's group and associativity with the expression you are reading. Copy a symbol or example when useful, and add explicit parentheses in your own code when the intended grouping should be unmistakable.
For example, searching 14 locates assignment rows in this page's numbering. That number is only a local lookup label; the C grammar does not assign an official precedence number 14.
Use cases
See how the tool fits into real work and everyday tasks.
When a condition combines comparisons, bitwise operations, and && or ||, filter those categories and compare their grouping. Parenthesize the expression if another reader could misread the intended test.
Search ++ or -- to see prefix and postfix rows separately. Their grouping differs, and their examples distinguish the two forms; do not collapse them into one precedence entry.
During code review or study, search a token, inspect its category and associativity, then compare the example with the expression in context. The table helps locate rules quickly; it does not parse or validate your source code.
Q&A
Find concise answers to common questions and confusing cases.
No. In this page's display, group 1 is the tightest and group 15 is the loosest. These numbers are for sorting and searching, not language-standard numbering.
No. Associativity describes how same-level operators are grouped. For example, subtraction chains group left to right, but that does not establish a universal execution order for every subexpression.
No. It is a curated operator reference based on common C expression forms, with some Objective-C syntax in its entries and examples. It is not a complete grammar, compiler, or check of language-version and type rules.
They have different precedence: postfix value++ binds more tightly than prefix ++value. The separate rows make that distinction visible.
Notes
Review scope, result limitations, and important precautions before use.
The descriptions and examples are reference material, not executable tests. They do not check whether an expression is valid for a particular type, compiler mode, SDK, or language version. Some operators also have operand constraints that a precedence chart cannot show.
Precedence and associativity determine expression grouping; they do not by themselves settle operand evaluation order, side effects, short-circuit behavior, or every sequencing rule. Avoid relying on a visual rank to infer those details. Consult the applicable language specification and compiler documentation for code where those distinctions affect behavior, and use parentheses to make intended grouping clear.
Related
Discover related tools, collections, and available API capabilities.