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

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

概述虽然我几乎一直使用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 interpre 虽然我几乎一直使用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的数组.

总结

以上是内存溢出为你收集整理的c – 如何破译指针数组的复杂声明?全部内容,希望文章能够帮你解决c – 如何破译指针数组的复杂声明?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1220195.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存