C ++: Operator priority list

Source: Internet
Author: User

Precedence Operator Description Example Associativity
1 ()
[]
->
.
::
++
--
Grouping Operator
Array access
Member access from a pointer
Member access from an object
Scoping Operator
Post-Increment
Post-Decrement
(A + B)/4;
Array [4] = 2;
PTR-> age = 34;
OBJ. Age = 34;
Class: age = 2;
For (I = 0; I <10; I ++ )...
For (I = 10; I> 0; I --)...
Left to right
2 !
~
++
--
-
+
*
&
(Type)
Sizeof
Logical Negation
Bitwise Complement
Pre-Increment
Pre-Decrement
Unary minus
Unary plus
Dereference
Address
Cast to a given type
Return size in bytes
If (! Done )...
Flags = ~ Flags;
For (I = 0; I <10; ++ I )...
For (I = 10; I> 0; -- I )...
Int I =-1;
Int I = + 1;
Data = * PTR;
Address = & OBJ;
Int I = (INT) floatnum;
Int size = sizeof (floatnum );
Right to left
3 -> *
.*
Member pointer Selector
Member pointer Selector
PTR-> * Var = 24;
OBJ. * Var = 24;
Left to right
4 *
/
%
Multiplication
Division
Modulus
Int I = 2*4;
Float F = 10/3;
Int REM = 4% 3;
Left to right
5 +
-
Addition
Subtraction
Int I = 2 + 3;
Int I = 5-1;
Left to right
6 <
>
Bitwise shift left
Bitwise shift right
Int flags = 33 <1;
Int flags = 33> 1;
Left to right
7 <
<=
>
> =
Comparison less-
Comparison less-than-or-Equal-
Comparison greater-
Comparison geater-than-or-Equal-
If (I <42 )...
If (I <= 42 )...
If (I> 42 )...
If (I> = 42 )...
Left to right
8 =
! =
Comparison equal-
Comparison not-Equal-
If (I = 42 )...
If (I! = 42 )...
Left to right
9 & Bitwise AND Flags = flags & 42; Left to right
10 ^ Bitwise exclusive or Flags = flags ^ 42; Left to right
11 | Bitwise random sive (normal) or Flags = flags | 42; Left to right
12 && Logical and If (conditiona & conditionb )... Left to right
13 | Logical or If (conditiona | conditionb )... Left to right
14 ? : Ternary conditional (if-then-else) Int I = (A> B )? A: B; Right to left
15 =
+ =
-=
* =
/=
% =
& =
^ =
| =
<=
>>=
Assignment operator
Increment and assign
Decrement and assign
Multiply and assign
Divide and assign
Modulo and assign
Bitwise AND and assign
Bitwise exclusive or and assign
Bitwise random sive (normal) or and assign
Bitwise shift left and assign
Bitwise shift right and assign
Int A = B;
A + = 3;
B-= 4;
A * = 5;
A/= 2;
A % = 3;
Flags & = new_flags;
Flags ^ = new_flags;
Flags | = new_flags;
Flags <= 2;
Flags> = 2;
Right to left
16 , Sequential evaluation Operator For (I = 0, j = 0; I <10; I ++, J ++ )... Left to right

Http://www.cppreference.com/wiki/operator_precedence

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.