优先级运算符名称或含义使用形式结合方向说明1[]数组下标数组名[常量表达式]左到右()圆括号(表达式)/函数名(形参表).成员选择(对象)对象.成员名->成员选择(指针)对象指针->成员名2-负号运算符-常量右到左单目运算符(type)强制类型转换(数据类型)表达式++自增运算符++变量名单目运算符--自减运算符--变量名单目运算符*取值运算符*指针变量单目运算符&取地址运算符&变量名单目运算符!逻辑非运算符!表达式单目运算符~按位取反运算符~表达式单目运算符sizeof长度运算符sizeof(表达式)3/除表达式/表达式左到右双目运算符*乘表达式*表达式双目运算符%余数(取模)整型表达式%整型表达式双目运算符4+加表达式+表达式左到右双目运算符-减表达式-表达式双目运算符5<<左移变量<<表达式左到右双目运算符>>右移变量>>表达式双目运算符6>大于表达式>表达式左到右双目运算符>=大于等于表达式>=表达式双目运算符<小于表达式<表达式双目运算符<=小于等于表达式<=表达式双目运算符7==等于表达式==表达式左到右双目运算符!=不等于表达式!= 表达式双目运算符8&按位与表达式&表达式左到右双目运算符9^按位异或表达式^表达式左到右双目运算符10|按位或表达式|表达式左到右双目运算符11&&逻辑与表达式&&表达式左到右双目运算符12||逻辑或表达式||表达式左到右双目运算符13?:条件运算符表达式1? 表达式2: 表达式3右到左三目运算符14=赋值运算符变量=表达式右到左/=除后赋值变量/=表达式*=乘后赋值变量*=表达式%=取模后赋值变量%=表达式+=加后赋值变量+=表达式-=减后赋值变量-=表达式<<=左移后赋值变量<<=表达式>>=右移后赋值变量>>=表达式&=按位与后赋值变量&=表达式^=按位异或后赋值变量^=表达式|=按位或后赋值变量|=表达式15,逗号运算符表达式,表达式,…左到右从左向右顺序运算说明:同一优先级的运算符,运算次序由结合方向所决定。简单记就是:! > 算术运算符 > 关系运算符 > && > || > 赋值运算符OperatorDescriptionExampleOverloadableGroup 1(no associativity)::Scope resolution operatorClass::age = 2;NOGroup 2()Function callisdigit('1')YES()Member initalizationc_tor(int x, int y) : _x(x), _y(y*10){};YES[]Array accessarray = 2;YES->Member access from a pointerptr->age = 34;YES.Member access from an objectobj.age = 34;NO++Post-incrementfor( int i = 0; i < 10; i++ ) cout << i;YES--Post-decrementfor( int i = 10; i > 0; i-- ) cout << i;YESconst_castSpecial castconst_cast(type_from);NOdynamic_castSpecial castdynamic_cast(type_from);NOstatic_castSpecial caststatic_cast(type_from);NOreinterpret_castSpecial castreinterpret_cast(type_from);NOtypeidRuntime type informationcout « typeid(var).name();cout « typeid(type).name();NOGroup 3(right-to-left associativity)!Logical negationif( !done ) …YESnotAlternate spelling for !~Bitwise complementflags = ~flags;YEScomplAlternate spelling for ~++Pre-incrementfor( i = 0; i < 10; ++i ) cout << i;YES--Pre-decrementfor( i = 10; i > 0; --i ) cout << i;YES-Unary minusint i = -1;YES+Unary plusint i = +1;YES*Dereferenceint data = *intPtr;YES&Address ofint *intPtr = &data;YESnewDynamic memory allocationlong *pVar = new long;MyClass *ptr = new MyClass(args);YESnew []Dynamic memory allocation of arraylong *array = new long[n];YESdeleteDeallocating the memorydelete pVar;YESdelete []Deallocating the memory of arraydelete [] array;YES(type)Cast to a given typeint i = (int) floatNum;YESsizeofReturn size of an object or typeint size = sizeof floatNum;int size = sizeof(float);NOGroup 4->*Member pointer selectorptr->*var = 24;YES.*Member object selectorobj.*var = 24;NOGroup 5*Multiplicationint i = 2 * 4;YES/Divisionfloat f = 10.0 / 3.0;YES%Modulusint rem = 4 % 3;YESGroup 6+Additionint i = 2 + 3;YES-Subtractionint i = 5 - 1;YESGroup 7<>Bitwise shift rightint flags = 33 >> 1;YESGroup 8Comparison greater-thanif( i > 42 ) …YES>=Comparison greater-than-or-equal-toif( i >= 42 ) ...YESGroup 9==Comparison equal-toif( i == 42 ) ...YESeqAlternate spelling for ==!=Comparison not-equal-toif( i != 42 ) …YESnot_eqAlternate spelling for !=Group 10&Bitwise ANDflags = flags & 42;YESbitandAlternate spelling for &Group 11^Bitwise exclusive OR (XOR)flags = flags ^ 42;YESxorAlternate spelling for ^Group 12|Bitwise inclusive (normal) ORflags = flags | 42;YESbitorAlternate spelling for |Group 13&&Logical ANDif( conditionA && conditionB ) …YESandAlternate spelling for &&Group 14||Logical ORif( conditionA || conditionB ) ...YESorAlternate spelling for ||Group 15(right-to-left associativity)? :Ternary conditional (if-then-else)int i = (a > b) ? a : b;NOGroup 16(right-to-left associativity)=Assignment operatorint a = b;YES+=Increment and assigna += 3;YES-=Decrement and assignb -= 4;YES*=Multiply and assigna *= 5;YES/=Divide and assigna /= 2;YES%=Modulo and assigna %= 3;YES&=Bitwise AND and assignflags &= new_flags;YESand_eqAlternate spelling for &=^=Bitwise exclusive or (XOR) and assignflags ^= new_flags;YESxor_eqAlternate spelling for ^=|=Bitwise normal OR and assignflags |= new_flags;YESor_eqAlternate spelling for |=<<=Bitwise shift left and assignflags <<= 2;YES>>=Bitwise shift right and assignflags >>= 2;YESGroup 17throwthrow exceptionthrow EClass(“Message”);NOGroup 18,Sequential evaluation operatorfor( i = 0, j = 0; i < 10; i++, j++ ) …YES运算符结合性[ ] . ( ) (方法调用)从左向右! ~ ++ -- +(一元运算) -(一元运算)从右向左* / %从左向右+ -从左向右<< >> >>>从左向右< <= > >= instanceof从左向右== !=从左向右&从左向右^从左向右|从左向右&&从左向右||从左向右?:从右向左=从右向左一个特殊的例子:public class stlye{public static void main(String[] args){int a=10,b=6;System.out.println("改变之前的数:a="+a+",b="+b);a-=b++;System.out.println("改变之后的数:a="+a+",b="+b);}}运算结果为:改变之前的数:a=10,b=6改变之后的数:a=4,b=7因为b++运算中先执行++,再返回后置++运算表达式(b++)的返回值(6)给-=运算符。在这个程序中a-=b++等于a=a-b++=10-6,所以a=4。优先级类别运算符1基本(x) x.y f(x) a[x] x++ x-- new typeof sizeof checked unchecked2单目+ - ! ~ ++x --x (T)x3乘法与除法* / %4加法与减法+ -5移位运算<< >>6关系运算< > <= >=7条件等== !=8位逻辑与&9位逻辑异或^10位逻辑或|11条件与&&12条件或‖13条件?:14赋值=一个特殊的例子:class Program{static void Main(string[] args){int a; a = 10; int b = 4;a += b++;Console.WriteLine("a={0}",a);Console.WriteLine("b={0}", b);Console.ReadLine();}}运算结果为:a=14b=5在这个程序中a+=b等于a=a+b=10+4,因为 b++ 时返回了一个临时变量后才进行自增。优先级类别运算符1取负-2乘方^3乘*3除/4四舍五入除/位移\5取模Mod6字符串合并& 或 +7加+7减-8相等=8大于>8大于等于>=8小于<8小于等于<=8不等于<>8同类对象Is8Like运算Like9非Not10与And11或Or12异或Xor13逻辑等Eqv14逻辑大于等于(蕴含)Imp