Topic: About References and Pointers


Author: "Ian Griffiths" <ian.griffiths@dmv.co.uk.no.spams.please>
Date: 1997/08/28
Raw View
Anand J. Bhalerao <anand@abnar-telsoft.com> wrote:
>
> 2> Pointer arithmetics on references don't work ;
> char  c[10] ;
> char &p = c[0] ;
> p++ ; // illegal

Not illegal, surely.  p++ in this context evaluates to the current value of
c[0], and also has a side effect of incrementing c[0].

Of course this is not pointer arithmetic.  If p were a pointer, the line
would also be legal, but would do something entirely different.


--
Ian Griffiths
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: "Anand J. Bhalerao" <anand@abnar-telsoft.com>
Date: 1997/08/29
Raw View
Ian Griffiths wrote in article <01bcb3df$a4d9d730$40c310ac@dmv-03477>...

>Anand J. Bhalerao <anand@abnar-telsoft.com> wrote:
>>
>> 2> Pointer arithmetics on references don't work ;
>> char  c[10] ;
>> char &p = c[0] ;
>> p++ ; // illegal
>
>Not illegal, surely.  p++ in this context evaluates to the current value of
>c[0], and also has a side effect of incrementing c[0].
>
>Of course this is not pointer arithmetic.  If p were a pointer, the line
>would also be legal, but would do something entirely different.
>

thanx for pointing out the wrong example. The expected result of the
operation should be included in the above statements.

BR, anand
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]