Priority List of C and C ++ Operators

Source: Internet
Author: User

 

C, C ++ operator Priority List 1. C language operator priority

Operators are arranged from top to bottom according to their priority values. operators in the same row have the same priority. The second line is all unary operators.
 

Operator Explanation Combination Method
() []->. Parentheses (functions, etc.), arrays, two types of structure member access From left to right
! ~ ++ -- +-

* & (Type) sizeof

Negative, bitwise negative, incremental, reduced, positive and negative,

Indirect, address fetch, type conversion, and Size Estimation

From right to left
*/% Multiplication, division, modulo From left to right
+- Add, subtract From left to right
<> Left shift, right shift From left to right
<<=>=> Less than, less than or equal to, greater than or equal to, greater From left to right
=! = Equal to, not equal From left to right
& Bitwise AND From left to right
^ Bitwise OR From left to right
| By bit or From left to right
&& Logic and From left to right
| Logic or From left to right
? : Condition From right to left
= + =-= * =/=

<=>>=

Various assignments From right to left
, Comma (Order) From left to right

 

2. c ++ operator priority

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 uation Operator For (I = 0, j = 0; I <10; I ++, J ++ )... 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.