C++ Operator Precedence

C++ Operator Precedence

source

  1. ::
  2. a++   a--   a()   a[]   a.   a->
  3. ++a   --a   +a   -a   !a   ~a   *a   &a   sizeof   new   delete
  4. .*   ->*
  5. a*b   a/b   a%b
  6. a+b   a-b
  7. a >> 1   a << 1
  8. <=> (Three-way comparision)
  9. <   <=   >   >=
  10. ==   !=
  11. a & b
  12. a ^ b
  13. a | b
  14. a && b
  15. a || b
  16. a ? b : c   throw   =   +=   -=   *=   /=   %=   <<=   >>=   &=   ^=   |=

Common Mistakes

TyposFixes
if (a & b == 0)=> if ((a & b) == 0)
if (a >> 2 + b > c)=> if ((a >> 2) + b > c)
*a.size()=> (*a).size()

C Pointers Declarations

Function call (e.g. f()) and array (e.g. a[]) has equal precedence, and both of them have higher precedence than reference (e.g. &a) and dereference (e.g. *a) operator.

See line 2 and line 5 below.

DeclarationMeaning
int *pa pointer to int
int *p[13]an array[13] of pointer to int
int *(p[13])an array[13] of pointer to int
int **pa pointer to a pointer to an int
int (*p)[13]a pointer to an array[13] of int
int *f()a function returning a pointer to int
int (*f)()a pointer to a function returning int
int (*(*f())[13])()a function returning ptr to an array[13] of pointers to functions returning int
int (*(*x[3])())[5]an array[3] of pointers to functions returning pointers to array[5] of ints
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值