指针指向的内容?? [英] contents of what a pointer points to??

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

问题描述

在K& RI中发现了这个:


静态字符allocbuf [ALLOCSIZE];

静态字符* allocp = allocbuf;


但是* allocp还没有设置为指向任何东西,所以怎么可能

使未知地址的内容成为allocbuf?


JS

In K&R I have found this:

static char allocbuf[ALLOCSIZE];
static char *allocp = allocbuf;

But *allocp has not been set to point at anything yet so how is it possible
to make the contents of an unknown address be "allocbuf"??

JS

推荐答案

JS写道:
在K& RI中发现了这个:

静态字符allocbuf [ALLOCSIZE];
静态字符* allocp = allocbuf;

但是* allocp还没有设置为指向任何东西,那么它是怎么回事可能
使未知地址的内容为allocbuf??
In K&R I have found this:

static char allocbuf[ALLOCSIZE];
static char *allocp = allocbuf;

But *allocp has not been set to point at anything yet so how is it possible
to make the contents of an unknown address be "allocbuf"??




它已被设置为指向某个东西,allocbuf []这是一块

内存。所以allocp指向allocbuf的第一个元素。



It has been set to point to something, allocbuf[] which is a block of
memory. So allocp points to the first element of allocbuf.


> static char * allocp = allocbuf;

^^^^^^^^^

如果你看起来更小心,你会看到allocp已被设置为

数组allocbuf的开头。 allocbuf基本上是指向数组的

内存位置的指针。


-

bjrnove

>
> static char *allocp = allocbuf;
^^^^^^^^^
If you look more careful you''ll see that allocp has been set to the
start of the array allocbuf. allocbuf is basicly a pointer to the
memorylocation for the array.

--
bjrnove




" Mark Odell" < OD ******* @ hotmail.com> skrev i en meddelelse

news:39 ************* @ individual.net ...

"Mark Odell" <od*******@hotmail.com> skrev i en meddelelse
news:39*************@individual.net...
JS写道:
在K& RI中发现了这个:

静态字符allocbuf [ALLOCSIZE];
静态字符* allocp = allocbuf;

但* allocp有还没有设置为指向任何东西,那么如何使
可以使未知地址的内容成为allocbuf??
In K&R I have found this:

static char allocbuf[ALLOCSIZE];
static char *allocp = allocbuf;

But *allocp has not been set to point at anything yet so how is it possible to make the contents of an unknown address be "allocbuf"??



它已被设置为点某事,allocbuf []这是一块内存。所以allocp指向allocbuf的第一个元素。



It has been set to point to something, allocbuf[] which is a block of
memory. So allocp points to the first element of allocbuf.




但是不应该写成:


1)static char * allocp; //声明* allocp是指向char的指针。

2)allocp =& allocbuf [0]; //使allocp指向

allocbuf中的第一个地址。

3)allocp = allocbuf; //与2相同只是一个简短的手。


然后我可以写:


* allocp = allocbuf;


这意味着allocp指向的地址的内容是

allocbuf的第一个元素。


JS



But should that not be written as:

1) static char *allocp; // declares that *allocp is a pointer to a char.
2) allocp = &allocbuf[0]; // makes allocp point to the first address in
allocbuf.
3) allocp = allocbuf; // the same as 2) just a short hand.

Then I can write:

*allocp = allocbuf;

which means that the contents of the address that allocp is pointing at is
the first element of allocbuf.

JS


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

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