according to the following
http://en.wikipedia.org/wiki/Reference_%28C%2B%2B%29
one reads :
C++ references differ from pointers in several essential ways:
* It is not possible to refer to a reference object directly after
it is defined; any occurrence of its name refers directly to the
object it references.
* As a consequence of the first point, neither arithmetic, casts,
nor any other operation can be performed on references except copying
their binding into other references.
* Once a reference is created, it cannot be later made to
reference another object; we say it cannot be reseated. This is often
done with pointers.
* References cannot be null, whereas pointers can; every reference
refers to some object, although it may or may not be valid.
* References cannot be uninitialized. Because it is impossible to
reinitialize a reference, they must be initialized as soon as they are
created. In particular, local and global variables must be initialized
where they are defined, and references which are data members of class
instances must be initialized in the class's constructor.
There is a simple conversion between pointers and references: the
address-of operator (&) will yield a pointer referring to the same
object when applied to a reference, and a reference which is
initialized from the dereference (*) of a pointer value will refer to
the same object as that pointer, where this is possible without
invoking undefined behavior. This equivalence is a reflection of the
typical implementation, which effectively compiles references into
pointers which are implicitly dereferenced at each use.
A consequence of this is that in many implementations , operating on a
variable with automatic or static lifetime through a reference,
although syntactically similar to accessing it directly, can involve
hidden dereference operations that are costly.
Also, because the operations on references are so limited, they are
also much easier to reason about formally than pointers, and harder to
cause errors with. While pointers can be made invalid through a
variety of mechanisms, ranging from carrying a null value to
out-of-bounds arithmetic to illegal casts to producing them from
random integers, a reference only becomes invalid in two cases:
* If it refers to an object with automatic allocation which goes
out of scope,
* If it refers to an object inside a block of dynamic memory which
has been freed.
The first is easy to detect automatically due to static scoping of
variables; the second is more difficult to assure, but it is the only
concern with references, and one suitably addressed by a reasonable
allocation policy.
hope it helps
friendly
jerome
On 1 Aug 2006 08:46:23 -0700, "Vols" <vo********@gma il.comwrote:
>If the people ask what is the different between pointer and reference,
what is the brief and good answer?
I say " pointer could point to NULL, but there is no null reference",
What is your opinion?
Vol