C + + operator precedence

Source: Internet
Author: User
Tags bitwise

Priority level

operator description examples of associativity
1 ()
[]
-
.
::
++
--
The parentheses operator that adjusts the precedence
Array Subscript access operator
To access a member's operator by pointing to the object's pointer
Operator that accesses members through the object itself
Scope operator
Post increment operator
Post-decrement operator
(A + B)/4;
ARRAY[4] = 2;
Ptr->age = 34;
Obj.age = 34;
Class::age = 2;
for (i = 0; i <; i++) ...
for (i = ten; i > 0; i--) ...
From left to right
2 !
~
+ +
--
-
+
*
&
(type)
sizeof
logical take inverse operator
bitwise Inverse ( Bitwise complement)
pre-increment operator
pre-decrement operator
unary take negative operator
unary positive operator
dereference operator
fetch address operator
type conversion operator
Returns the number of bytes occupied by the object operator
if (!done) ...
Flags = ~flags;
for (i = 0; i <; ++i) ...
for (i = ten; i > 0; i.) ...
int i =-1;
int i = +1;
data = *ptr;
Address = &obj;
int i = (int) floatnum;
int size = sizeof (floatnum);
From right to left
3 ->*

ptr->*var =;
Obj.*var =;
Left to right
4 *
/
%
multiplication operator
Division operator
fetch remainder operator
int i = 2 * 4;
float f = 10/3;
int rem = 4 3;
Left to right
5 +
-
addition operator
subtraction operator
int i = 2 + 3;
int i = 5-1;
Left to right
6 <<
>>
bitwise left shift operator
int flags = << 1;
int flags = >> 1;
Left to right
7 <
<=

>=
Less than the comparison operator
less than or equal to comparison operator
greater than comparison operator
greater than or equal to comparison operator
if (i < ) ...
if (i <=) ...
if (i >) ...
if (i >=) ...
Left to right
8 ==
!=
equals comparison operator
Not equal to comparison operator
if (i = = 42) ...
if (i! = 42) ...
From left to right
9 & Bitwise AND operator Flags = flags & 42; From left to right
10 ^ Bitwise XOR OR operator Flags = flags ^ 42; From left to right
11 | Bitwise OR operator Flags = Flags | 42; From left to right
12 && Logic and operators if (Conditiona && conditionb) ... From left to right
13 || Logical OR operator if (Conditiona | | conditionb) ... From left to right
14 ? : Ternary conditional operator int i = (a > B)? A:B; From right to left
15 =
+ =
-=
*=
/=
%=
&=
^=
|=
<<=
>>=
assignment operator
Compound assignment operator ( addition)
compound assignment operator (subtraction)
compound assignment operator (multiplication)
Compound assignment operator (division)
compound assignment operator (take surplus)
Compound assignment operator (bitwise VS)
Compound assignment operator (bitwise XOR)
Compound assignment operator (bitwise OR)
Compound assignment operator (bitwise left shift)
Compound assignment operator (bitwise right SHIFT)
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;
From right to left
16 , Comma operator for (i = 0, j = 0; i <; i++, J + +) ... From left to right

C + + operator precedence

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.