reference to a pointer

S

sam_cit

Hi Everyone,

I just came to know about a declartion, namely reference to a pointer
like the following,

int *&p; //p is a reference to a pointer to an integer

Is this valid only in C++ and not in C?

and i also came to know that there is a difference between call by
address and call by reference, can anyone tell me the exact difference?
 
R

Richard Heathfield

(e-mail address removed) said:
Hi Everyone,

I just came to know about a declartion, namely reference to a pointer
like the following,

int *&p; //p is a reference to a pointer to an integer

Is this valid only in C++ and not in C?

Whether it is valid in C++ is a question for a C++ reference book. It is not
valid in C.
and i also came to know that there is a difference between call by
address and call by reference, can anyone tell me the exact difference?

C does call-by-value. Always.
 
C

Chris Dollin

Hi Everyone,

I just came to know about a declartion, namely reference to a pointer
like the following,

int *&p; //p is a reference to a pointer to an integer

Is this valid only in C++ and not in C?

It's not valid C: C doesn't support a C++-style reference type.
and i also came to know that there is a difference between call by
address and call by reference, can anyone tell me the exact difference?

Suppose we have

int cbr( int REFERENCE x ) { x += 1; }

... int b = 16; cbr( b ); assert (b == 17); [1] ...

in some neuromatic C language with reference arguments. The
variable `x` is a reference to whatever variable is given
as actual argument: changing `x` changes the argument (and
vice-versa). Hence incrementing `x` increments `b`.

If we eliminate the REFERENCE magic, then assigning to `x`
doesn't affect the actual argument variable, and the assert
won't.

The user of the term "call by address" that I have seen (and
may have used ... beware circularity) looks like:

int cba( int *x ) { *x += 1; }

... cbr( &b ); ...

The address of the object is explicitly passed and the
indirect manipulation of that object is signalled by the
`*` operator.

"Call by address" is what C (programmers) use(s) to compensate
for C not having "call by reference".

That's my story and I'm sticking to it.

[1] A fake `assert` keyword. Pretend its the macro or
a printf or whatever.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top