Stroustrup 5.1指针 [英] Stroustrup 5.1 Pointers

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

问题描述

在本章的开头,我看到一些声明我无法理解。我知道指针获取一个

变量的地址,如果我们想要操纵该变量,则有用。每个函数获取其参数的私有副本
<


char c;


char ** ppc; //指针指针的用途是什么?

int * a [15]; //为什么有必要使用数组如果指针

而不是数组int


int(* fp)(char *); //我们可以通过使用它的名称调用一个函数,然后

为什么指向一个函数的指针。这里。


int * f(char *); //我无法理解这一点。





在这个新手点,我不需要理解这些东西。在一个

的comp.lang.c ++中档案,我读到这些事情变得更容易,这样的问题一旦开始构建就会消失现实生活中的软件,或者使用C ++做一些现实生活中的编码。

at the very beginning of the chapter, i see some statements i am
unable to understand. i know the "Pointer" takes the address of a
variable, useful if, in case, we want to manipulate that variable as
each Function gets its private copy of arguments:

char c;

char** ppc; // what is the use of "pointer to pointer"

int* a[15]; // why it is necessary to have "an array if pointers"
instead of array of "int"

int (*fp) (char*); // we can call a function by using its name, then
why "pointer to a function" here.

int* f(char*); // i am unable to comprehend this.

OR

at this newbie "point", i dont need to understand this stuff. In one
of the "comp.lang.c++" archives, i read that these things become
easier and problems like this disappear as soon as one starts building
real life softwares or one does some real-life coding using C++.

推荐答案

arnuld写道:

::在本章的开头,我看到一些陈述我是

::无法理解。我知道指针获取一个

::变量的地址,如果我们想要操作该变量,那么这个变量非常有用。每个函数获取其参数的私有副本:< br $> b $ b ::

:: char c;

::

:: char ** ppc; //指针指针的用途是什么?


如果您的变量本身就是指针,那么这很有用(通常不会:-),而且你是

仍然想操纵它。


::

:: int * a [15]; //为什么有必要使用数组如果指针

::而不是数组int


这可能很有用。不过很常见。


::

:: int(* fp)(char *); //我们可以通过使用它的名称调用函数,

::那么为什么指向函数的指针这里。


如果你有一个指向函数的指针,你可以为它指定一个类似函数的地址。这可以让你改变你所调用的功能。


也不经常使用。 :-)


::

:: int * f(char *); //我无法理解这一点。


这里有两个指针,一个是函数f的参数,另一个是

是返回值f。


这与int(* fp)(char *)不同,其中fp是指针,而int是返回类型的
。这里''int *''是(非指针)函数返回的结果。


不要太在意。 :-)


::

::或

::

:: at this newbiepoint,我不需要了解这些东西。在一个

::的comp.lang.c ++中档案,我读到这些东西变得更容易了,这样的问题一旦开始就会消失

::构建现实生活中的软件或者做一些真实的生活编码使用

:: C ++。


您可能不必了解所有细节。在C ++代码中使用或操作raw

指针并不常见。其中大部分都可以隐藏在标准容器内。

Bo Persson
arnuld wrote:
:: at the very beginning of the chapter, i see some statements i am
:: unable to understand. i know the "Pointer" takes the address of a
:: variable, useful if, in case, we want to manipulate that variable as
:: each Function gets its private copy of arguments:
::
:: char c;
::
:: char** ppc; // what is the use of "pointer to pointer"

This is useful (not often :-) if your variable is itself a pointer, and you
still want to manipulate it.

::
:: int* a[15]; // why it is necessary to have "an array if pointers"
:: instead of array of "int"

It could be useful. Not very often though.

::
:: int (*fp) (char*); // we can call a function by using its name,
:: then why "pointer to a function" here.

If you have a pointer to a function, you can assign it the address of a
similar function. That lets you change what function you call.

Not used very often either. :-)

::
:: int* f(char*); // i am unable to comprehend this.

You have two pointers here, one is a parameter to the function f, the other
is the return value of f.

This is different from int (*fp)(char*), where fp is a pointer, and int is
the return type. Here ''int*'' is what the (non-pointer) function f returns.

Don''t bother to much. :-)

::
:: OR
::
:: at this newbie "point", i dont need to understand this stuff. In one
:: of the "comp.lang.c++" archives, i read that these things become
:: easier and problems like this disappear as soon as one starts
:: building real life softwares or one does some real-life coding using
:: C++.

You probably don''t have to know all the details. Using or manipulating raw
pointers is not very common in C++ code. Most of that can be hidden inside
the standard containers.
Bo Persson


* arnuld:
* arnuld:

在本章的开头,我看到一些陈述我是b $ b无法理解的。我知道指针获取一个

变量的地址,如果我们想要操纵该变量,则有用。每个函数获取其参数的私有副本
<


char c;


char ** ppc; //指针指针的用途是什么?

int * a [15]; //为什么有必要使用数组如果指针

而不是数组int


int(* fp)(char *); //我们可以通过使用它的名称调用一个函数,然后

为什么指向一个函数的指针。这里。


int * f(char *); //我无法理解这一点。
at the very beginning of the chapter, i see some statements i am
unable to understand. i know the "Pointer" takes the address of a
variable, useful if, in case, we want to manipulate that variable as
each Function gets its private copy of arguments:

char c;

char** ppc; // what is the use of "pointer to pointer"

int* a[15]; // why it is necessary to have "an array if pointers"
instead of array of "int"

int (*fp) (char*); // we can call a function by using its name, then
why "pointer to a function" here.

int* f(char*); // i am unable to comprehend this.



除了第一个声明之外,这些都是指针的例子。


询问它们的用途是没有意义的,请问

上面的''c'的目的是什么毫无意义。


也许文本有一些示例代码或文本上面的声明引用了

的例子,或者它们只是例子。


-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:热门帖子。

问:usenet和电子邮件中最烦人的事情是什么?

Except the first declaration, these are all examples of pointers.

Asking what they''re for is meaningless, just as it''s meaningless to ask
what the purpose of ''c'' above is.

Perhaps the text has some example code or textual examples that refer to
the above declarations, or perhaps they''re just examples.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


3月26日上午10点34分,arnuld < geek.arn ... @ gmail.comwrote:
On Mar 26, 10:34 am, "arnuld" <geek.arn...@gmail.comwrote:

at this newbie" point",我不需要了解这些东西。在一个

的comp.lang.c ++中档案,我读到这些事情变得更容易,这样的问题一旦开始构建就会消失现实生活中的软件,或者使用C ++做一些现实生活中的编码。
at this newbie "point", i dont need to understand this stuff. In one
of the "comp.lang.c++" archives, i read that these things become
easier and problems like this disappear as soon as one starts building
real life softwares or one does some real-life coding using C++.



恕我直言,TC ++ PL作为参考比作为教程更好。

根据你的背景,考虑Glassborow的任何一个的书

或者Koening& Moo的加速C ++。

IMHO, TC++PL serves MUCH better as a reference than as a tutorial.
Depending upon your background, consider either of Glassborow''s books
or perhaps Koening & Moo''s Accelerated C++.


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

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