How to we return two values from a function? - C
This is a discussion on How to we return two values from a function? - C ; Hi all,
Is there any way to return two values from a
function ....................
Thanks,
jayapal...
-
How to we return two values from a function?
Hi all,
Is there any way to return two values from a
function ....................
Thanks,
jayapal
-
Re: How to we return two values from a function?
On Mon, 29 Oct 2007 21:31:49 -0700, jayapal <jayapal403@gmail.com>
wrote:
>Hi all,
>
>Is there any way to return two values from a
>function ....................
Yes and no.
You can't do something like this:
int double foo(void)
{
int i = 5;
double d = 10.0;
return i d;
}
But you can do something like this:
struct bar1
{
int i;
double d;
};
struct bar1 foo1(void)
{
struct bar1 b;
b.i = 5;
b.d = 10.0;
return b;
}
/* or this: */
struct bar2
{
int i;
double d;
};
void foo2(struct bar2 *out_bar2_ptr)
{
out_bar2_ptr->i = 5;
out_bar2_ptr->d = 10.0;
}
/* or even this: */
void foo3(int *i_ptr, double *d_ptr)
{
*i_ptr = 5;
*d_ptr = 10.0;
}
Regards
--
jay
-
Re: How to we return two values from a function?
jayapal <jayapal403@gmail.com> wrote:
# Hi all,
#
# Is there any way to return two values from a
# function ....................
(1) Return a struct.
(2) Pass in variable addresses and assign the result thereto.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
Raining down sulphur is like an endurance trial, man. Genocide is the
most exhausting activity one can engage in. Next to soccer.
-
Re: How to we return two values from a function?
jayapal <jayapal403@gmail.com> writes:
> Is there any way to return two values from a
> function ....................
You could put the two values into a struct and return that
struct, or you could "return" one of the values by passing a
pointer to an object as one of the function's arguments.
If you can give a better description of the problem that you are
trying to solve, perhaps we can provide a more specific solution.
--
http://footstool.stanford.edu/~blp/private/out.jpeg
-
Re: How to we return two values from a function?
On Mon, 29 Oct 2007 21:58:37 -0700, Ben Pfaff <blp@cs.stanford.edu>
wrote:
[snip]
>--
> http://footstool.stanford.edu/~blp/private/out.jpeg
Congratulations Ben on completing your doctorate program, as noted in
the above URL that you posted in your sig. Your contributions to this
newsgroup are much appreciated. I'd hire you in a standard
CLOCKS_PER_SEC heartbeat.
Best wishes for your future and best regards
--
jaysome
-
Re: How to we return two values from a function?
Ben Pfaff said:
> http://footstool.stanford.edu/~blp/private/out.jpeg
Richly deserved. Congratulations!
--
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
-
-
Re: How to we return two values from a function?
"Richard Heathfield" <rjh@see.sig.invalid> a écrit dans le message de news:
yfSdnaBElsj4VLvanZ2dnUVZ8rGdnZ2d@bt.com...
> Ben Pfaff said:
>
>> http://footstool.stanford.edu/~blp/private/out.jpeg
>
>
> Richly deserved. Congratulations!
Seconded.
What was the subject of your thesis ?
--
Chqrlie.
-
Re: How to we return two values from a function?
Charlie Gordon wrote, On 30/10/07 07:39:
> "Richard Heathfield" <rjh@see.sig.invalid> a écrit dans le message de news:
> yfSdnaBElsj4VLvanZ2dnUVZ8rGdnZ2d@bt.com...
>> Ben Pfaff said:
>>
>>> http://footstool.stanford.edu/~blp/private/out.jpeg
>>
>> Richly deserved. Congratulations!
>
> Seconded.
>
> What was the subject of your thesis ?
"The impact of hyper-pedants on programming." Why else has he been
hanging around here?
Congratulations Ben.
--
Flash Gordon
-
Re: How to we return two values from a function?
Charlie Gordon said:
>
> "Richard Heathfield" <rjh@see.sig.invalid> a écrit dans le message de
> news: yfSdnaBElsj4VLvanZ2dnUVZ8rGdnZ2d@bt.com...
>> Ben Pfaff said:
>>
>>> http://footstool.stanford.edu/~blp/private/out.jpeg
>>
>>
>> Richly deserved. Congratulations!
>
> Seconded.
>
> What was the subject of your thesis ?
My guess: literate programming?
--
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
Similar Threads
-
By Application Development in forum C
Replies: 0
Last Post: 10-29-2007, 11:37 PM
-
By Application Development in forum C
Replies: 0
Last Post: 10-29-2007, 11:35 PM
-
By Application Development in forum verilog
Replies: 4
Last Post: 05-17-2007, 03:21 PM
-
By Application Development in forum Clipper
Replies: 3
Last Post: 04-24-2007, 07:34 AM
-
By Application Development in forum c++
Replies: 6
Last Post: 12-20-2006, 11:24 PM