你怎么破译指针+阵列复杂的声明? [英] How do you decipher complex declarations of pointers+arrays?

查看:119
本文介绍了你怎么破译指针+阵列复杂的声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我用的std ::矢量几乎所有的时间,我感兴趣的是理解,尽我所能关于指针。我所讲的例子:

Although I use std::vector almost all the time, I am interested in understanding as much as I can about pointers. Examples of what I am talking about:

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

我感兴趣的是该声明的precise定义。

I am interested in the precise definition of this declaration.

推荐答案

不只是指针和数组:的如何跨preT复杂的C / C ++声明的:

Not just pointers and arrays: 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。

Is an array of 5 pointers to char.

这篇关于你怎么破译指针+阵列复杂的声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆