C + + operator precedence

Source: Internet
Author: User
Tags bitwise

Priority level

Operator

Describe

Example

Binding nature

1

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

Array subscript access operator
operator that accesses a member through a pointer to an object
operator that accesses a member through the object itself
scope operator
Post-increment operator
Post-decrement operator

(A + b)/4;
Array[4] = 2;
Ptr->age = under;
O Bj.age = 34;
Class::age = 2;
for (i = 0; i <; i++) ...
for (i = ten; i > 0; i--) ...

2

!
~
+ +
--
-
+< br> *
&
(type)
sizeof

bitwise inverse (bitwise fetch) &NBSP;
Pre-increment operator
Pre-decrement operator
unary minus 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);

3

->*
.*

Operator that accesses a member on a pointer through a pointer to a member
Operator that accesses a member on an object by pointing to a pointer to a member

Ptr->*var = 24;
Obj.*var = 24;

From left to right

4

*
/
%

Multiplication operator
Division operator
Take remainder operator

int i = 2 * 4;
float F = 10/3;
int rem = 4% 3;

From left to right

5

+
-

Addition operator
Subtraction operator

int i = 2 + 3;
int i = 5-1;

From left to right

6

<<
>>

Bitwise left SHIFT operator
Bitwise RIGHT SHIFT operator

int flags = << 1;
int flags = >> 1;

From left to right

7

<
<=
>
>=

Less than comparison operators
Less than or equal to comparison operators
Greater than comparison operator
Greater than or equal to comparison operator

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

From 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 operators (bitwise AND)
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

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.