pointer variable vs reference variables

S

sulekhasweety

dear all,


can anyone explain the differences between pointer variable and
reference variables ?
 
S

santosh

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.
 
T

Tomás Ó hÉilidhe

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;
}
 
R

rahul

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,166
Messages
2,570,907
Members
47,448
Latest member
DeanaQ4445

Latest Threads

Top