Multiple function output

This is a discussion on Multiple function output within the C++ Programming forums, part of the General Programming Boards category; the comments should be replace with what ever code is need to grab the variables from the function, and yes ...

  1. #16
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    the comments should be replace with what ever code is need to grab the variables from the function, and yes i did modify the function and test the program, it gave:

    116
    116
    Make sure you are actually passing by reference (i.e. prefacing variable names with '&').

    Code:
    void function(int &a, int &b)
    {
      a *= 2;
      b /= 4;
    }
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  2. #17
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110
    yes i did that, it still gives
    116
    116

  3. #18
    Registered User
    Join Date
    Mar 2002
    Posts
    249
    Post the code you have written so far.
    Well, there are a few things wrong with your code:

    1) It does not work.
    2) It does not work.
    3) It does not work.

    Hope this helps.

  4. #19
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Strange indeed. The following code works just as advertised:

    Code:
    void function(int &a, int &b)
    {
      a *= 2;
      b /= 4;
    }
    
    int main()
    {
      int a, b;
      a = 1;
      b = 16;
    
      function(a, b);
      // code to get variable values from function()
      cout << a << b <<endl;
    
      function(a, b);
      // code to get variable values from function()
      cout << a << b <<endl;
    
      return 0;
    }
    There must be some minor discrepancy somewhere.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  5. #20
    Registered User
    Join Date
    Mar 2002
    Posts
    249
    If you pass it by value, the output is:

    116
    116

    If you pass it by refrence, the output is:

    24
    41

    So I'm not sure what your're doing wrong...
    Well, there are a few things wrong with your code:

    1) It does not work.
    2) It does not work.
    3) It does not work.

    Hope this helps.

  6. #21
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110
    FD9> whats your source, mine matches the source Zach gave

  7. #22
    Registered User
    Join Date
    Mar 2002
    Posts
    249
    FD9> whats your source, mine matches the source Zach gave
    So does mine...Hey! I'm kinda getting use to being called FD9. Sounds alot cooler. Try copy & past. Make sure it's exactly the same code. That's all I can tell ya.
    Well, there are a few things wrong with your code:

    1) It does not work.
    2) It does not work.
    3) It does not work.

    Hope this helps.

  8. #23
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110
    didn't notice the '=' in the function, it works now, thanks

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 04:33 AM
  2. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 10:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21