Thread: more than one return parameter

  1. #1
    Unregistered
    Guest

    Question more than one return parameter

    I am having problems finding infromation on using the &x I know how it is used... I am just wondering about general functions that return more than one parameter, looking for practical examples...

  2. #2
    A function can only return one parameter. You could i suppose return a pointer to an array or struct of data though.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  3. #3
    Unregistered
    Guest
    I mean &x pointers, for instance one example I have is adding, subtracting, and multiplying 2 different numbers, and having the results returned... but I need other practical examples

  4. #4
    zoo
    Guest
    Here's a simple example.

    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
       double a, b, s, d, p, q;
       cout << "Enter two numbers:";
       cin >> a >> b;
       calculate(a,b,s,d,p,q);
       cout << a << "+" << b << "=" << s << endl;
       cout << a << "-" << b << "=" << d << endl;
       cout << a << "*" << b << "=" << p << endl;
       cout << a << "/" << b << "=" << q << endl;
       return 0;
    }
    
    void calculate(double a, double b, double &sum, double &dif, double &prod, double &quot)
    {
       sum = a + b;
       dif = a - b;
       prod = a * b;
       quot = a / b;
    }

  5. #5
    Unregistered
    Guest
    thanks for example... but that is the one I already have... I was looking for other practical examples...

  6. #6
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    References or else pointers are the best way to go. Use the example, it's very practical. If you have a group of data than create a class and pass it by reference to the caller.
    I compile code with:
    Visual Studio.NET beta2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to combine these working parts??
    By transgalactic2 in forum C Programming
    Replies: 0
    Last Post: 02-01-2009, 08:19 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  4. DirectInput help
    By Muphin in forum Game Programming
    Replies: 2
    Last Post: 09-10-2005, 11:52 AM
  5. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM