Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > reference to a pointer

Reply
Thread Tools

reference to a pointer

 
 
sam_cit@yahoo.co.in
Guest
Posts: n/a
 
      12-17-2006
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?

 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      12-17-2006
http://www.velocityreviews.com/forums/(E-Mail 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.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
 
Reply With Quote
 
 
 
 
Chris Dollin
Guest
Posts: n/a
 
      12-18-2006
(E-Mail Removed) 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/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pointer to pointer or reference to pointer A C++ 7 07-05-2011 07:49 PM
Reference counting and API (const reference vs pointer oriented) mathieu C++ 8 08-31-2008 09:05 AM
reference and pointer-reference kasthurirangan.balaji@gmail.com C++ 4 12-24-2007 09:05 PM
Pointer-to-pointer-to-pointer question masood.iqbal@lycos.com C Programming 10 02-04-2005 02:57 AM
Passing the value by reference is same as pointer by reference sam pal C++ 3 07-16-2003 09:14 PM



Advertisments