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...
Printable View
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...
A function can only return one parameter. You could i suppose return a pointer to an array or struct of data though.
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
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 ")
{
sum = a + b;
dif = a - b;
prod = a * b;
quot = a / b;
}
thanks for example... but that is the one I already have... I was looking for other practical examples...
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.