C ++ operator precedence

Source: Internet
Author: User
ArticleDirectory
    • C ++ operator precedence
C ++ operator precedence

The operators at the top of this list are evaluated first.

Precedence Operator Description Example Associativity
1 :: Scoping Operator Class: age = 2; None
2 ()
[]
->
.
++
--
grouping operator
array access
member access from a pointer
member access from an object
post- increment
post-Decrement
(A + B)/4;
array [4] = 2;
PTR-> age = 34;
obj. age = 34;
for (I = 0; I <10; I ++ )...
for (I = 10; I> 0; I --)...
left to right
3 !
~
++
--
-
+
*
&
(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
4 -> *
.*
Member pointer Selector
Member object Selector
PTR-> * Var = 24;
OBJ. * Var = 24;
Left to right
5 *
/
%
Multiplication
Division
Modulus
Int I = 2*4;
Float F = 10/3;
Int REM = 4% 3;
Left to right
6 +
-
Addition
Subtraction
Int I = 2 + 3;
Int I = 5-1;
Left to right
7 <
>
Bitwise shift left
Bitwise shift right
Int flags = 33 <1;
Int flags = 33> 1;
Left to right
8 <
<=
>
> =
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
9 =
! =
Comparison equal-
Comparison not-Equal-
If (I = 42 )...
If (I! = 42 )...
Left to right
10 & Bitwise AND Flags = flags & 42; Left to right
11 ^ Bitwise exclusive or Flags = flags ^ 42; Left to right
12 | Bitwise random sive (normal) or Flags = flags | 42; Left to right
13 && Logical and If (conditiona & conditionb )... Left to right
14 | Logical or If (conditiona | conditionb )... Left to right
15 ? : Ternary conditional (if-then-else) Int I = (A> B )? A: B; Right to left
16 =
+ =
-=
* =
/=
% =
&=
^=
|=< BR ><=< BR >>=
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
17 , sequential evaluation operator for (I = 0, j = 0; I <10; I ++, J ++ )... left to right

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.