home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11516 < prev    next >
Encoding:
Internet Message Format  |  1992-07-23  |  1.1 KB

  1. Path: sparky!uunet!dtix!darwin.sura.net!mips!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!destroyer!ubc-cs!mala.bc.ca!epp
  2. From: epp@mala.bc.ca (Lorne Epp)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How can I return two value to a procedure ???
  5. Message-ID: <1992Jul23.065635.590@mala.bc.ca>
  6. Date: 23 Jul 92 13:56:35 GMT
  7. References: <9207222041.AA00524@honeydew.cis.ohio-state.edu>
  8. Organization: Malaspina College
  9. Lines: 25
  10.  
  11. In article <9207222041.AA00524@honeydew.cis.ohio-state.edu>, ychung@news.cis.ohio-state.edu (yiu fai chung) writes:
  12. > I would like to return two values of two variables.
  13. > How can I do that ?
  14.  
  15. Just delete your return statement:
  16.  
  17. > void change_value( int *i, int *j )    /* arguments are pointers to ints */
  18. > {
  19. >   *i = 2;        /* These lines alter the values of the variables */
  20. >   *j = 3;        /* that the arguments point to. */
  21. >   return (*i, *j);    /* delete this line */
  22. > }
  23.  
  24. You would call the function like this:
  25.  
  26. int a=10,b=11;
  27.  
  28. change_value( &a, &b );        /* change_value expects pointer-to-int
  29.                    arguments, so you pass address-of a
  30.                    and b.    */
  31.  
  32. /* Value of a is now 2; b is 3 */
  33.  
  34. Lorne Epp
  35. epp@mala.bc.ca
  36.