473,468 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

pointer variable vs reference variables

dear all,
can anyone explain the differences between pointer variable and
reference variables ?
Jun 27 '08 #1
9 2308
su***********@gmail.com wrote:
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.programming might be a better place to post this question.

Jun 27 '08 #2
On Jun 7, 8:25*am, sulekhaswe...@gmail.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:

void Func(int const *p)
{
# define i (*p)

i = 5;
}
Jun 27 '08 #3
* * void Func(int &i) { p = 5; }

i = 5;
Jun 27 '08 #4
On Jun 7, 9:05*am, Tomás Ó hÉilidhe <t...@lavabit.comwrote:
* * void Func(int const *p) { *p = 5; }

int *const p

* * void Func(int const *p)

int *const p

I should go back to bed.
Jun 27 '08 #5

<su***********@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.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Jun 27 '08 #6
su***********@gmail.com ha scritto:
can anyone explain the differences between pointer variable and
reference variables ?
It is useless since "reference variables" is not C.
Jun 27 '08 #7
On Jun 7, 2:19 pm, "Malcolm McLean" <regniz...@btinternet.comwrote:
References exist in Java and C++, and are basically syntactic sugar for
pointers. They point only to one object, and may never be null.
A bit off the topic, but references can be null in Java. References in
Java work
like constant pointers in C.

Jun 27 '08 #8
Malcolm McLean wrote:
>
<su***********@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: NullPointerException.)

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>

--
Eric Sosman
es*****@ieee-dot-org.invalid
Jun 27 '08 #9
"Eric Sosman" <es*****@ieee-dot-org.invalidwrote in message
Malcolm McLean wrote:
>>
<su***********@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: NullPointerException.)

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?

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Mon | last post by:
I am in the process of reorganizing my code and came across and I came across a problem, as described in the subject line of this posting. I have many classes that have instances of other classes...
34
by: wilson | last post by:
Hi All, I am a novice at C and just have learned pointer for a short period. Today one error had occured while executing my program below. And I cannot find the error out since it's checked "OK"...
18
by: man | last post by:
can any one please tell me what is the diff between pointer and reference.....and which one is better to use ....and why???????
7
by: Xiaoshen Li | last post by:
Dear All, I thought I understood using pointer variables as function parameters. But I failed to understand why it is needed pass-by-reference of a pointer variable. To me, pointer variable...
51
by: Kuku | last post by:
What is the difference between a reference and a pointer?
14
by: Vols | last post by:
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...
14
by: Ian | last post by:
I am looking at porting code from a C++ application to C#. This requires implementing data sharing functionality similar to what is provided by a smart pointer in C++. I have only recently begun...
12
by: Luca | last post by:
I have 2 questions: 1. Which one is the best: Returning member variables of the class by const ref or returning by pointer? e.g.: Employee* GetEmployee() const; Employee& ...
33
by: Ney André de Mello Zunino | last post by:
Hello. I have written a simple reference-counting smart pointer class template called RefCountPtr<T>. It works in conjunction with another class, ReferenceCountable, which is responsible for the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.