C + + priority list (reprint)

Source: Internet
Author: User
Tags bitwise modulus

Note: The article is reproduced in the network.

C-priority list
Precedence Operator Description Example Associativity

()
[]
->
.
::
+ +
- -

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 <; i++) ...
for (i = ten; i > 0; i--) ...

 

 

Left-to-right

2

!
~
+ +
--
-
+
*
&
(type)
sizeof

Logical Negation
Bitwise complement
Pre-increment
pre-decrement
unary minus
unary plus
dereference
Address of
Cast to a given type
Return size in bytes

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);








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 = << 1;
int flags = >> 1;

Left to right

7

<
<=
>
>=

Comparison Less-than
Comparison less-than-or-equal-to
Comparison Greater-than
Comparison geater-than-or-equal-to

if (I < 42) ...
if (i <= 42) ...
if (i > 42) ...
if (i >= 42) ...

Left to right

8

==
!=

Comparison equal-to
Comparison not-equal-to

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 inclusive (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;

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 inclusive (normal) OR and assign
Bitwise shift left and as Sign
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 <; i++, J + +) ...

Left to right

C + + priority list

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 <; i++) ...
for (i = ten; i > 0; i--) ...







left to right

!
~
+ +
--
-
+
*
&
(type)
sizeof

Logical Negation
Bitwise complement
Pre-increment
pre-decrement
unary minus
unary plus
dereference
Address of
Cast to a given type
Return size in bytes

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);








Right-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 = << 1;
int flags = >> 1;

Left to right
7

<
<=
>
>=

Comparison Less-than
Comparison less-than-or-equal-to
Comparison Greater-than
Comparison geater-than-or-equal-to

if (I < 42) ...
if (i <= 42) ...
if (i > 42) ...
if (i >= 42) ...





Left to right
8

==
!=

Comparison equal-to
Comparison not-equal-to

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 inclusive (normal) OR Flags = Flags | 42; Left to right
12 && Logical and if (Conditiona && conditionb) ... Left to right
13 || Logical OR int i = (a > B)? A:b Left to right
: Ternary conditional (if-then-else) if (Conditiona | | conditionb) ... right to left

=
+ =
-=
*=
/=
% =
&=
^=
|=
<<=
>>=

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 inclusive (normal) OR and assign
Bitwise shift left and as Sign
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
Sequential evaluation operator left to right
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.