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使它指向其他的对象



你可能感兴趣的:(C语言声明优先级(precedence rule))