指针问题......最后一天? :-)

问题描述:

有一件事困扰了我一段时间(好吧,不止一件事!)。


如果我有一个功能:


foo(char * s){


char * t = s;


......

s ++; < ---几次任意时间


}


现在......我的问题是这个。


是t独立于s,意思是:


1)在s ++之后它仍然指向s的开头吗?


2)我想与1有关,如果我现在评价* t,它会是s中的第一个

字符吗?


谢谢......那是'它为今天!!!

One thing has puzzled me a while ( well, more than one thing!).

If I have a function:

foo( char *s){

char *t = s;

......
s++; <<--- a few arbitrary times

}

Now...my question is this.

Is "t" independent of s, in the sense of:

1) Will it still point to the beginning of s, after s++ ?

2) I guess related to 1, if I now evaluate *t, will it be the first
character in s?

Thanks...that''s it for today!!!

" mdh" < md ** @ comcast.netwrote in message

news:d8 **************************** ****** @ l17g2000 pri.googlegroups.com ...
"mdh" <md**@comcast.netwrote in message
news:d8**********************************@l17g2000 pri.googlegroups.com...

有一件事困扰了我一段时间(好吧,不止一件事!)。


如果我有一个功能:


foo(char * s){
One thing has puzzled me a while ( well, more than one thing!).

If I have a function:

foo( char *s){



地址s的副本传递给foo。

A copy of the address s is passed to foo.


char * t = s;
char *t = s;



如果将复制的地址放入指针t,我们会存储一份副本。

We store a copy if the copied address into pointer t.


.....


s ++; < ---几次任意次
.....
s++; <<--- a few arbitrary times



我们将推送到函数中的地址的副本增加几个

时间。

We increment the copy of the address that was pushed into the function a few
times.


}


现在......我的问题是这个。


是t独立于s,意思是:


1)在s ++之后它还会指向s的开头吗?
}

Now...my question is this.

Is "t" independent of s, in the sense of:

1) Will it still point to the beginning of s, after s++ ?



当然。

Of course.


2)我想与1相关,如果我现在评估* t,它会成为s中的第一个

角色吗?
2) I guess related to 1, if I now evaluate *t, will it be the first
character in s?



我想K& R2第5章会有所帮助。

**发自 http://www.teranews.com **

I guess that K&R2 Chapter 5 will be helpful.
** Posted from http://www.teranews.com **


5月5日, 10:52 pm,mdh< m ... @ comcast.netwrote:
On May 5, 10:52 pm, mdh <m...@comcast.netwrote:

有一件事困扰了我一段时间(好吧,不止一件事!)。


如果我有一个功能:


foo(char * s){


char * t = s;


.....


s ++; < ---几次任意时间


}


现在......我的问题是这个。


是t独立于s,意思是:


1)在s ++之后它仍然指向s的开头吗?


2)我想与1有关,如果我现在评价* t,它会是s中的第一个

字符吗?


谢谢......那是'它今天!
One thing has puzzled me a while ( well, more than one thing!).

If I have a function:

foo( char *s){

char *t = s;

.....

s++; <<--- a few arbitrary times

}

Now...my question is this.

Is "t" independent of s, in the sense of:

1) Will it still point to the beginning of s, after s++ ?

2) I guess related to 1, if I now evaluate *t, will it be the first
character in s?

Thanks...that''s it for today!!!



在尝试之前,有什么东西可以让你困惑

看看会发生什么?
>
-

Robert Gamble

How long does something have to puzzle you before you give it a try
and see what happens?

--
Robert Gamble


5月5日,7:59 * pm,Dann Corbit < dcor ... @ connx.comwrote:
On May 5, 7:59*pm, "Dann Corbit" <dcor...@connx.comwrote:

>
>

Ist独立于s,意思是:
Is "t" independent of s, in the sense of:


1)在s ++之后它还会指向s的开头吗?
1) Will it still point to the beginning of s, after s++ ?



当然。


Of course.



由于某种原因我有这个概念性概念,即当s增加时,它会导致t看到与s相同的原始数组部分。什么

你说的是,一旦新的指针被初始化,它会独立地运作
并可以这样使用?

For some reason I had this conceptual notion that as s is incremented,
it causes t to "see" the same part of the original array as s. What
you are saying is that once the new pointer is initialized, it acts
independently and can be used as such?

>