Return Multiple Values at a time from Function

How can we return multiple values at a time from function using call by reference?

Showing Answers 1 - 2 of 2 Answers

BALASUBRAMANIAM

  • Jan 7th, 2017
 

Create a struct and set two values inside and return the struct variable. You have to allocate space for the char * in your program. Use pointers as your function parameters. Then use them to return multiple value

  Was this answer useful?  Yes

jbode

  • Feb 2nd, 2017
 

Assuming I understand your question correctly, see the attached code snippet for an example.

Code
  1. /**

  2.  * Write to the parameters output, another_output, and even_more_output

  3.  */

  4. void foo( int input, int *output, int *another_output, int *even_more_output )

  5. {

  6.   do_something_with( input );

  7.   *output = some_value();

  8.   *another_output = some_other_value();

  9.   *even_more_output = yet_another_value();

  10. }

  11.  

  12. void bar( void )

  13. {

  14.   int x, y, z;

  15.  

  16.   foo( 1, &x, &y, &z );

  17.   // do something with x, y, and z

  18. }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions