On May 5, 11:06 pm, mdh <m...@[EMAIL PROTECTED]
> wrote:
> On May 5, 7:59 pm, "Dann Corbit" <dcor...@[EMAIL PROTECTED]
> wrote:
>
>
>
> > > Is "t" independent of s, in the sense of:
>
> > > 1) Will it still point to the beginning of s, after s++ ?
>
> > Of course.
>
> 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?
s and t are distinct objects, both of which point to the same place
initially, for example, say they both point to the string "abc":
s
|
V
+-+-+-+--+
|a|b|c|\0|
+-+-+-+--+
^
|
t
After you execute s++, s points to the next character in the string:
s
|
V
+-+-+-+--+
|a|b|c|\0|
+-+-+-+--+
^
|
t
but t is unchanged. If you modify the data that s points to, i.e.
*s='e' :
s
|
V
+-+-+-+--+
|a|e|c|\0|
+-+-+-+--+
^
|
t
and then access the data through t you will see "aec" since they both
point into the same, now modified, object.
--
Robert Gamble


|