指向许多示例的指针 [英] Pointer to pointer with lots of examples

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

问题描述

任何人都可以帮助我理解指针指向

的例子吗?


提前申请。


Sagar

Can anyone help me in getting to understand pointer to pointer with
examples?

Appritiate in advance.

Sagar

推荐答案

sheroork说:
sheroork said:

任何人都可以帮助我理解指针指向

的例子?
Can anyone help me in getting to understand pointer to pointer with
examples?



打电话给目录查询服务(如果你在英国,则为192)。告诉

他们是你要找的人的名字,他们会告诉你

相关的电话号码。然后,您可以使用该电话号码联系您真正想与之交谈的

人。


翻译:指针告诉您某事情在哪里。但它本身有一个

地址,你可能需要先找到它才能使用它。所以指向指针的
指针只是告诉你特定指针的位置。一个

指针就像一个电话号码。取消引用指针就像调用

一样。当另一端的人给你另一个电话号码时,

你刚用一个指针(*他的*号码)指针(他给出的号码)

)),大概你会用这个新指针找到你真正想找的信息

(打电话)。


例子很棘手,因为任何现实的工作示例都可能太大而且太复杂,无法使它成为一个有用的例子。如果你不是害怕大的例子,请告诉我,我会看到我可以从我的代码库中挖掘出来的价值。
/>

-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)

Phone up the Directory Enquiries service (192 if you''re in the UK). Tell
them the name of the person you''re looking for, and they''ll tell you the
relevant phone number. You can then use that phone number to contact the
person you really want to talk to.

Translation: a pointer tells you where something is. But it, itself, has an
address, which you might need to find out before you can use it. So a
pointer to pointer simply tells you where a particular pointer is. A
pointer is like a phone number. Dereferencing the pointer is like making
the call. When the guy on the other end gives you another phone number,
you''ve just used a pointer (*his* number) to a pointer (the number he gives
you), and presumably you''ll use that new pointer to find the information
(make the call) you really wanted to find (make).

Examples are tricky, in that any realistic working example is likely to be
way too big and complicated to make it a useful example. If you''re not
afraid of big examples, though, let me know and I''ll see what I can dig up
from my code base.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


sheroork写道:
sheroork wrote:

任何人都可以通过

示例来帮助我理解指向指针的指针吗?
Can anyone help me in getting to understand pointer to pointer with
examples?



int ** p;


p

+ --- +

| ? |

+ --- +


p = malloc(sizeof * p);


p * p

+ --- + + --- +

| -----> | ? |

+ --- + + --- +


* p = malloc(sizeof ** p);


p * p ** p

+ --- + + --- + + --- +

| -----> | -----> | ? |

+ --- + + --- + + --- +


** p = 7;


p * p ** p

+ --- + + --- + + --- +

| -----> | -----> | 7 |

+ --- + + --- + + --- +

八月

int **p;

p
+---+
| ? |
+---+

p = malloc(sizeof *p);

p *p
+---+ +---+
| ----->| ? |
+---+ +---+

*p = malloc(sizeof **p);

p *p **p
+---+ +---+ +---+
| ----->| ----->| ? |
+---+ +---+ +---+

**p = 7;

p *p **p
+---+ +---+ +---+
| ----->| ----->| 7 |
+---+ +---+ +---+
August


Richard Heathfield< in ***** @ invalid.invalidwrites:
Richard Heathfield <in*****@invalid.invalidwrites:

sheroork说:
sheroork said:

> ;任何人都可以通过
示例帮助我理解指向指针的指针吗?
>Can anyone help me in getting to understand pointer to pointer with
examples?



示例很棘手,因为任何实际的工作示例都可能太大而且太复杂,无法使其成为一个有用的示例。如果你不是害怕大事,那么,让我知道,我会看到我可以从我的代码库中挖掘出来的b $ b。


Examples are tricky, in that any realistic working example is likely to be
way too big and complicated to make it a useful example. If you''re not
afraid of big examples, though, let me know and I''ll see what I can dig up
from my code base.



使用指向指针的指针从

函数返回一个指针值可能是一个简单的方法来提出一个简短的例子。

-

int main(void){char p [] =" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz。\

\ n",* q =" kl BIcNBFr.NKEzjwCIxNJC" ;; int i = sizeof p / 2; char * strchr(); int putchar(\

); while(* q){i + = strchr(p ,* q ++) - p; if(i> =(int)sizeof p)i- = sizeof p-1; putchar(p [i] \

);} return 0;}

Using a pointer to pointer to return a pointer value from a
function may be a simple way to come up with a short example.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}


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

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