加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 如何破译指针数组的复杂声明?

发布时间:2020-12-16 10:26:40 所属栏目:百科 来源:网络整理
导读:虽然我几乎一直使用std :: vector,但我仍然对尽可能多地理解指针感兴趣.我在谈论的例子: char* array[5]; // What does it mean?// 1) pointer to an array of 5 elements!// 2) an array of 5 pointers? 我对这一宣言的准确定义感兴趣. 解决方法 不只是指
虽然我几乎一直使用std :: vector,但我仍然对尽可能多地理解指针感兴趣.我在谈论的例子:

char* array[5]; // What does it mean?
// 1) pointer to an array of 5 elements!
// 2) an array of 5 pointers?

我对这一宣言的准确定义感兴趣.

解决方法

不只是指针和数组: How to interpret complex C/C++ declarations:

Start reading the declaration from the
innermost parentheses,go right,and
then go left. When you encounter
parentheses,the direction should be
reversed. Once everything in the
parentheses has been parsed,jump out
of it. Continue till the whole
declaration has been parsed.

One small change to the right-left
rule: When you start reading the
declaration for the first time,you
have to start from the identifier,and
not the innermost parentheses.

你的例子:

char* array[5];

是一个5个指向char的数组.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读