C语言使用需要注意的地方

1. 运算法优先级

Precedence

Operator

Description

Associativity

highest

::

Scope resolution (C++ only)

Left-to-right

2

++

Suffix increment

--

Suffix decrement

()

Function call

[]

Array subscripting

.

Element selection by reference

->

Element selection through pointer

typeid()

Run-time type information(C++ only) (see typeid)

const_cast

Type cast (C++ only) (see const cast)

dynamic_cast

Type cast (C++ only) (see dynamic_cast)

reinterpret_cast

Type cast (C++ only) (see reinterpret cast)

static_cast

Type cast (C++ only) (see static cast)

3

++

Prefix increment

Right-to-left

--

Prefix decrement

+

Unary plus

-

Unary minus

!

Logical NOT

~

Bitwise NOT

(type)

Type cast

*

Indirection (dereference)

&

Address-of

sizeof

Size-of

new, new[]

Dynamic memory allocation (C++ only)

delete, delete[]

Dynamic memory deallocation (C++ only)

4

.*

Pointer to member (C++ only)

Left-to-right

->*

Pointer to member (C++ only)

5

*

Multiplication

/

Division

%

Modulo(remainder)

6

+

Addition

-

Subtraction

7

<<

Bitwiseleft shift

>>

Bitwiseright shift

8

<

Less than

<=

Less than or equal to

>

Greater than

>=

Greater than or equal to

9

==

Equal to

!=

Not equal to

10

&

Bitwise AND

11

^

Bitwise XOR (exclusive or)

12

|

Bitwise OR (inclusive or)

13

&&

Logical AND

14

||

Logical OR

15

?:

Ternaryconditional (see ?:)

Right-to-left

16

=

Direct assignment

+=

Assignment by sum

-=

Assignment by difference

*=

Assignment by product

/=

Assignment by quotient

%=

Assignment by remainder

<<=

Assignment by bitwise left shift

>>=

Assignment by bitwise right shift

&=

Assignment by bitwise AND

^=

Assignment by bitwise XOR

|=

Assignment by bitwise OR

17

throw

Throw operator (exceptions throwing, C++ only)

18

,

Comma

Left-to-right


2. 左移、右移运算法

位移运算符分为算术位移(Arithmetic Shift)和逻辑位移(Logic Shift):算术位移时,移出的位被丢弃,移进的位在左移(Left Shift)时补0;右移(Right Shift)时补符号位,保证符号位不变。逻辑位移时,移出的位被丢弃,移进的位不论左移和右移都补0。另外,当移动的位数超过类型的长度时,将会对位数取余数,按余数进行移位。

如:10100110 >>5(假设字长为8),则得到的是 11111101

10100110 >>13,得到的也是11111101。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值