By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,478 Members | 1,703 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,478 IT Pros & Developers. It's quick & easy.

Call-by-Reference

P: n/a
Does C have Call-By-Reference for a function??

I think it doesn't. Am I right?
Nov 9 '08 #1
Share this Question
Share on Google+
15 Replies


P: n/a
Technically speaking, does C have Call-By-Reference for a function??
I think it doesn't. Am I right?
Nov 9 '08 #2

P: n/a
co**************@gmail.com wrote:
Technically speaking, does C have Call-By-Reference for a function??
I think it doesn't. Am I right?
You are right: C function arguments are passed by value.

An argument value can, of course, be a pointer -- that is,
the argument value can refer to another object. But the
argument itself is always passed by value.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Nov 9 '08 #3

P: n/a
co**************@gmail.com writes:
Does C have Call-By-Reference for a function??
Not directly, no; all parameters are passed by value. But of course
you can do the equivalent by passing pointers.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 9 '08 #4

P: n/a
co**************@gmail.com wrote:
Does C have Call-By-Reference for a function??

I think it doesn't. Am I right?
There is no call-by reference in C but
int func(int&a);
is call-by-reference in c++
Nov 10 '08 #5

P: n/a
Michael said:
co**************@gmail.com wrote:
>Does C have Call-By-Reference for a function??

I think it doesn't. Am I right?
There is no call-by reference in C but
int func(int&a);
is call-by-reference in c++
No, in C++ it's a declaration, not a call of any kind. And in C, it's just
a syntax error.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 10 '08 #6

P: n/a
On 9 Nov, 18:53, Eric Sosman <esos...@ieee-dot-org.invalidwrote:
coolguyaround...@gmail.com wrote:
Technically speaking, does C have Call-By-Reference for a function??
I think it doesn't. Am I right?

* * *You are right: C function arguments are passed by value.
you mean "wrong"?
>
* * *An argument value can, of course, be a pointer -- that is,
the argument value can refer to another object. *But the
argument itself is always passed by value.

--
Nick Keighley
Nov 10 '08 #7

P: n/a
Nick Keighley said:
On 9 Nov, 18:53, Eric Sosman <esos...@ieee-dot-org.invalidwrote:
>coolguyaround...@gmail.com wrote:
Technically speaking, does C have Call-By-Reference for a function??
I think it doesn't. Am I right?

You are right: C function arguments are passed by value.

you mean "wrong"?
No, he means "right", and he's right to mean that. The OP said he thinks
that C *doesn't* have call by reference. First, he asked whether it did,
and then he said he thinks not. He's right.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 10 '08 #8

P: n/a
In article <ln************@nuthaus.mib.orgKeith Thompson <ks***@mib.orgwrites:
co**************@gmail.com writes:
Does C have Call-By-Reference for a function??

Not directly, no; all parameters are passed by value. But of course
you can do the equivalent by passing pointers.
That is not the same as call by reference. With call by reference the
only place where you actually can *see* it is call by reference is in
the header of a function. Not in the body, nor in the actual call.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 10 '08 #9

P: n/a
"Dik T. Winter" <Di********@cwi.nlwrites:
In article <ln************@nuthaus.mib.orgKeith Thompson
<ks***@mib.orgwrites:
co**************@gmail.com writes:
Does C have Call-By-Reference for a function??
>
Not directly, no; all parameters are passed by value. But of course
you can do the equivalent by passing pointers.

That is not the same as call by reference. With call by reference the
only place where you actually can *see* it is call by reference is in
the header of a function. Not in the body, nor in the actual call.
Yes, I know it's not the same thing, but it can be used to achieve
exactly the same effect.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 10 '08 #10

P: n/a
Nick Keighley wrote:
Eric Sosman <esos...@ieee-dot-org.invalidwrote:
>coolguyaround...@gmail.com wrote:
>>Technically speaking, does C have Call-By-Reference for a
function?? I think it doesn't. Am I right?

You are right: C function arguments are passed by value.

you mean "wrong"?
No, you are wrong. The normal reading is handled by "C function
arguments are passed by value". The off-beat reading is handled by
the fact that C does NOT have "Call-By-Reference".

A third possible reading is that you are asserting "C function
arguments are passed by wrong".

:-) (and you are wrong)

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Nov 10 '08 #11

P: n/a
Nick Keighley wrote:
On 9 Nov, 18:53, Eric Sosman <esos...@ieee-dot-org.invalidwrote:
>coolguyaround...@gmail.com wrote:
>>Technically speaking, does C have Call-By-Reference for a function??
I think it doesn't. Am I right?
You are right: C function arguments are passed by value.

you mean "wrong"?
If I remember right, I didn't mean "wrong" -- but I could be
wrong, right?

Two wrongs don't make a right, but three lefts do.

--
Er*********@sun.com
Nov 10 '08 #12

P: n/a
Eric Sosman wrote:
....
Two wrongs don't make a right, but three lefts do.
I miss street grids! Where I currently live, three left turns often
get me on a dead-end street, and usually get me lost - they are seldom
the equivalent of a right turn.
Nov 10 '08 #13

P: n/a
jameskuyper wrote:
Eric Sosman wrote:
...
>Two wrongs don't make a right, but three lefts do.

I miss street grids! Where I currently live, three left turns
often get me on a dead-end street, and usually get me lost -
they are seldom the equivalent of a right turn.
You are allowed to move out of Boston. :-)

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Nov 11 '08 #14

P: n/a
jameskuyper wrote:
Eric Sosman wrote:
...
> Two wrongs don't make a right, but three lefts do.

I miss street grids! Where I currently live, three left turns often
get me on a dead-end street, and usually get me lost - they are seldom
the equivalent of a right turn.
where I live 3 rights re likely to make a left, but three lefts will, on
average, get you in trouble with the police twice...

Bye, Jojo
Nov 11 '08 #15

P: n/a
CBFalconer wrote:
jameskuyper wrote:
>Eric Sosman wrote:
...
>>Two wrongs don't make a right, but three lefts do.
I miss street grids! Where I currently live, three left turns
often get me on a dead-end street, and usually get me lost -
they are seldom the equivalent of a right turn.

You are allowed to move out of Boston. :-)
It's actually the Maryland suburbs of Washington, DC.
Nov 11 '08 #16

This discussion thread is closed

Replies have been disabled for this discussion.