C语言声明优先级(precedence rule)

以下文字摘自expert c programming

A    Declarations are read by starting with the name and then reading in precedence order.


B The precedence, from high to low, is:
B.1 parentheses grouping together parts of a declaration
B.2 the postfix operators:
parentheses () indicating a function, and
square brackets [] indicating an array.
B.3 the prefix operator: the asterisk denoting "pointer to".


C      If a const and/or volatile keyword is next to a type specifier (e.g. int, long, etc.) it

applies to the type specifier. Otherwise the const and/or volatile keyword applies to the

pointer asterisk on its immediate left.

个人觉得这里next to理解为adjacent to而不是after,中文版的译者翻译成的是after的意思。

相当于说const,volatile与类型说明符刚好挨着,那么它修饰类型说明符。否则它与左边的*(星号)左结合,修饰左边的星号


const int * grape


const 修饰int,代表常量,grape为指向const int类型的指针


int const * grape

const修饰int,const int与int const等价


int* const grape_jelly

这里const修饰的是*,意味着grape_jelly是个指针常量

不能修改 grape_jelly使它指向其他的对象



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值