关于指针和引用语法 [英] About pointer and reference syntax

查看:101
本文介绍了关于指针和引用语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尴尬,虽然它可能是我知道我不是唯一一个有这个问题。

Embarrassing though it may be I know I am not the only one with this problem.

我一直使用C / C ++和关闭多年。我从来没有把握的概念问题的地址的,指针指向指针的指针和引用。

I have been using C/C++ on and off for many years. I never had a problem grasping the concepts of addresses, pointers, pointers to pointers, and references.

我不断地发现自己绊倒前$ P $在C语法pssing他们,但是。没有基础知识,例如声明或提领,但更多的时候喜欢的东西得到一个指针到指针,或指针的地址来引用等基本上任何一个去的一级或二级超越常态间接。通常情况下我与运营商的各种半逻辑组合,摸索,直到我在正确的跳闸。

I do constantly find myself tripping over expressing them in C syntax, however. Not the basics like declarations or dereferencing, but more often things like getting the address of a pointer-to-pointer, or pointer to reference, etc. Essentially anything that goes a level or two of indirection beyond the norm. Typically I fumble with various semi-logical combinations of operators until I trip upon the correct one.

沿线某处显然我错过了一个规则或两个简化并让这一切水到渠成。所以我想我的问题是:你知道一个网站或参考,涵盖这一事项,清晰度和一些深度

Clearly somewhere along the line I missed a rule or two that simplifies and makes it all fall into place. So I guess my question is: do you know of a site or reference that covers this matter with clarity and in some depth?

推荐答案

我发现的右 - 左 - 右规则是有用的。它会告诉你如何读的声明,让你得到所有的指针和引用秩序。例如:

I found the right-left-right rule to be useful. It tells you how to read a declaration so that you get all the pointers and references in order. For example:

int *foo();

使用右 - 左 - 右规则,可以为foo是一个返回指向整数的功能。

Using the right-left-right rule, you can translate this to English as "foo is a function that returns a pointer to an integer".

int *(*foo)();  // "foo is a pointer to a function returning a pointer to an int"
int (*foo[])();  // "foo is an array of pointers to functions returning ints"

右 - 左 - 右规则的大部分解释对于C而不是C ++写的,所以他们往往离开了引用。他们的工作就像在这种情况下指针。

Most explanations of the right-left-right rule are written for C rather than C++, so they tend to leave out references. They work just like pointers in this context.

int &foo;  // "foo is a reference to an integer"

这篇关于关于指针和引用语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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