wrote:
> 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.
--
Chris "HO. HO. HO." Dollin
"Who do you serve, and who do you trust?" /Crusade/