dear all,
>
>
can anyone explain the differences between pointer variable and
reference variables ?
You'll have to ask in a C++ group (comp.lang.c++) or in a group
appropriate to whatever language you are using (presumably it contains
both pointers and references, hence your question). C has no
references. If you want language independent responses, then
comp.programmin g might be a better place to post this question.
On Jun 7, 8:25 am, sulekhaswe...@g mail.com wrote:
dear all,
>
can anyone explain the differences between pointer variable and
reference variables ?
References don't exist in C, they're a C++ thing. A reference is
simply a pointer with the following features:
* You don't have to dereference it, it gets dereferenced
automagically
* You can't change what it points to
So the following two are equivalent:
void Func(int const *p) { *p = 5; }
void Func(int &i) { p = 5; }
If you want references in C, then you can play around with macroes:
dear all,
>
>
can anyone explain the differences between pointer variable and
reference variables ?
>
References exist in Java and C++, and are basically syntactic sugar for
pointers. They point only to one object, and may never be null. However the
variable is passed as an address, ie a pointer.
>dear all,
>>
>>
>can anyone explain the differences between pointer variable and
>reference variables ?
>>
References exist in Java and C++, and are basically syntactic sugar for
pointers. They point only to one object, and may never be null. However
the variable is passed as an address, ie a pointer.
<off-topic>
Dunno about C++, but what you say about Java is wrong on
all three points (or at least on two and a half points, allowing
some wiggle room in interpreting "they" in the second point):
1) A Java "reference" *is* what C calls a "pointer," not a
pointer hiding behind a sugar-coated facade. (Java gives
the programmer little freedom to manipulate its pointers,
but they're indisputably pointers. Note what's thrown for
misuse of a null reference: NullPointerExce ption.)
2) A Java reference value refers to only one object, just as
a C pointer value refers to only one object. A Java
reference variable, just like a C pointer variable, can
refer to different objects at different times.
3) A Java reference value or variable can be null.
Re: [OT] Re: pointer variable vs reference variables
"Eric Sosman" <esosman@ieee-dot-org.invalidwrot e in message
Malcolm McLean wrote:
>>
><sulekhasweety @gmail.comwrote in message news:
>>dear all,
>>>
>>>
>>can anyone explain the differences between pointer variable and
>>reference variables ?
>>>
>References exist in Java and C++, and are basically syntactic sugar for
>pointers. They point only to one object, and may never be null. However
>the variable is passed as an address, ie a pointer.
>
<off-topic>
>
Dunno about C++, but what you say about Java is wrong on
all three points (or at least on two and a half points, allowing
some wiggle room in interpreting "they" in the second point):
>
1) A Java "reference" *is* what C calls a "pointer," not a
pointer hiding behind a sugar-coated facade. (Java gives
the programmer little freedom to manipulate its pointers,
but they're indisputably pointers. Note what's thrown for
misuse of a null reference: NullPointerExce ption.)
>
2) A Java reference value refers to only one object, just as
a C pointer value refers to only one object. A Java
reference variable, just like a C pointer variable, can
refer to different objects at different times.
>
3) A Java reference value or variable can be null.
>
</off-topic>
>
Java references can be null, fair point. The rest of this post is singularly
useless and unhelpful. Do you appreciate why?
Comment