解读C++声明

char *const cp ; // const pointer to char 
char const * pc ; // pointer to const char
const char * pc2 ; // pointer to const char 

Some people find it helpful to read such declarations right to left. For example, "cp is a const pointer to a char" and "pc2 is a pointer to a char const ."

如何复杂的表达式声明,掌握了方法一样可以读出来。首先,()和[]具有比*更高的优先级。因此先读[],读作 array of,*读作pointer to。当然()具有最高的优先级,如果()里没有内容类似 returntype (* function)()的,读作function。

char (*(*x())[])(),从里面往外读 , x is a function returning pointer to D,读到这里可以进行一个简化, char(*D)[](),继续读,D is array of function returning char。因此: function returning pointer to array[] of  pointer to function returning char

char (*(*x[3])())[5]  --->> char(*D)())[5],x is array3 of pointer to , D is function return char[5]。

这是我比较好理解的方法,写的也比较粗糙。更详细请参考这里:

http://blog.chinaunix.net/u/12783/showart_378340.html

  1. int
  2. int *
  3. int *[3]
  4. int (*)[]
  5. int *()
  6. int (*[])(void)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值