Home

Summercool wrote:

>
> Can we confirm the following? also someone said, Java also has
> "reference" like in C++, which is an "implicit pointer":

Java references are neither like C++ references nor like C++ pointers. They
are something in between.

> in the C era, a pointer *is* a reference.

Depending on how you define "reference", you could say that.

> Until when C++ comes along, then we have a new "reference":
>
> int a = 10;
> int i =& a; // or int i = &a; i am not sure about the syntax.

It doesn't matter. Whitespace before and after the & operator is ignored.

> i = 20; // now both a and i are 20
>
> so this type of reference is an implicit pointer... it points to a,
> but you don't use the way in C (int *pi = &a) And when you use (i = 20),
> it does the dereference silently. (*pi = 20;)
>
> so a reference is new: a pointer but "looks like not a pointer".

A reference in C++ is another name for an already existing object. After its
initialization, it behaves just like the object it refers to.

> So from this point on, a reference and a pointer are not the same... a
> reference is a pointer "that doesn't look like a pointer."
>
> they both points to something. but the syntax (or grammar) of usage
> doesn't look like it is a pointer in the C era. a reference is an
> "automatically dereferenced" pointer, shall we say? or an "implicit"
> pointer, or "silent" pointer.

No, it isn't. A pointer can be null, a reference can't. A pointer can be
uninitialized, a reference can't.

> In language we use nowadays, which language has "reference" to a
> "reference"?

That's another thing you can't have in C++. You can have a pointer to
pointer, but you can't have a reference to reference, because references
are not objects (unlike pointers).

previous
next

Maximum size
Re: Sets in Python
Re: ANN: Compyler 0.1
Re: how to get command output using python
Re: setuptools without unexpected downloads
Fundacja Hobbit
Dzieci Niczyje
Akogo
Podaruj Zycie
Fundacja Avalon