About const

摘抄几段Dan Saks对const的讲解:

 

     typedef void * VP;

Type specifiers contribute to the type of the declarator-id; other specifiers provide nontype information that applies directly to the declarator-id.

The order in which the declaration specifiers appear in a declaration doesn't matter. Thus, for example,
     const VP vectorTable[]
is equivalent to:
     VP const vectorTable[]
and
     const void *vectorTable[]
is equivalent to:
     void const *vectorTable[]


The only declaration specifiers that can also appear in declarators are const and volatile.
For example, the const in:
     void *const vectorTable[]


The order of the declaration specifiers doesn’t matter to the compiler. Therefore, these declarations are equivalent:
     const void *vectorTable[]
     void const *vectorTable[]

 

 

于是下面的声明就好理解了。

     const int * p;              //表示p所指向的内容为只读

     int const * p;              //同上

     int * const p;              //表示p为只读

     const int * const p;    //表示p及其指向的内容都为只读

     int const * const p;    //同上

 

     char * const * (*next)();   //表示next是一个指向函数的指针,函数的返回值为指向char类型只读指针的指针。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值