文档章节

C/C++优先级列表

follitude
 follitude
发布于 2016/07/30 11:12
字数 751
阅读 15
收藏 0

C优先级列表

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

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 inclusive (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 evaluation operator

for( i = 0, j = 0; i < 10; i++, j++ ) ...

left to right

 

C++优先级列表

 

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 of
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-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
14 ? : Ternary conditional (if-then-else) if( conditionA || conditionB ) ... 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 inclusive (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 evaluation operator for( i = 0, j = 0; i < 10; i++, j++ ) ... left to right

本文转载自:http://www.cnblogs.com/chenglei/archive/2009/08/03/1537822.html

follitude
粉丝 6
博文 118
码字总数 4956
作品 0
浦东
私信 提问
Python 使用 Protocol Buffers 的 C 语言拓展将更快

Protocol Buffers (类似XML的一种数据描述语言)最新版本2.3里,protoc—py_out命令只生成原生的Python代码。 尽管PB(Protocol Buffers)可以为C++语言生成快速解析和序列化代码,但是这种...

toil
2014/11/03
1K
0
C语言编程学习运算符的优先级和结合性

C语言是面向过程的,而C++是面向对象的 C和C++的区别: C是一个结构化语言,它的重点在于算法和数据结构。C程序的设计首要考虑的是如何通过一个过程,对输入(或环境条件)进行运算处理得到...

小辰带你看世界
2018/05/25
0
0
STL系列之五 priority_queue 优先级队列

priority_queue 优先级队列是一个拥有权值概念的单向队列queue,在这个队列中,所有元素是按优先级排列的(也可以认为queue是个按进入队列的先后做为优先级的优先级队列——先进入队列的元素...

彭博
2012/04/12
1K
0
C++雾中风景番外篇:理解C++的复杂声明与声明解析

在学习C系列语言的过程之中,理解C/C++的复杂声明一直是初学者很困扰的问题。笔者初学之时也深受困扰,对很多规则死记硬背。后续在阅读《C专家编程》之后,尝试在编译器的角度来理解C/C++的声...

LeeHappen
2018/09/05
0
0
STL系列之五 priority_queue 优先级队列

priority_queue 优先级队列是一个拥有权值概念的单向队列queue,在这个队列中,所有元素是按优先级排列的(也可以认为queue是个按进入队列的先后做为优先级的优先级队列——先进入队列的元素...

长平狐
2012/12/10
60
0

没有更多内容

加载失败,请刷新页面

加载更多

从濒临解散到浴火重生,OceanBase 这十年经历了什么?

阿里妹导读:谈及国产自研数据库,就不得不提 OceanBase。与很多人想象不同的是,OceanBase 并非衔着金钥匙出生的宠儿。相反,它曾无人看好、困难重重,整个团队甚至数度濒临解散。 从危在旦...

阿里云云栖社区
25分钟前
2
0
比特币第三方API大全

在开发比特币应用时,除了使用自己搭建的节点,也可以利用第三方提供的比特币api,来获取市场行情、进行交易支付、查询账户余额等。这些第三方api不一定遵循标准的比特币rpc接口规范,但往往...

汇智网教程
37分钟前
1
0
Dozer:Dozer异常java.lang.ClassCastException

这个问题是个很难发现的问题,因为代码本身没有错误,但就是无法找到报错原因 现记录下这个报错 java.lang.ClassCastException:com.XXX.ObjectA cannot be cast to com.XXX.ObjectA 代码中并...

琴兽
今天
2
0
Feign Retryer的默认重试策略测试

1、Feign配置 @Configurationpublic class FeignConfig { @Value("${coupon_service.url:http://localhost:8081}") private String couponServiceUrl; @Bean publ......

moon888
今天
2
0
关于不同域名下的session共享问题

如果登录,首页,分类,列表,产品都在不同的二级域名下,主域名不变,一定要保证里面的版本问题,不能为了更新而更新,这样哪个下面的session都访问不了。

dragon_tech
今天
5
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部