tried using return(5,4); but this is an syntax error.
That is not a syntax error. (5,4)
is a valid expression and here ,
is an operator. So the expression (5,4)
evaluates to the rightmost operand, which is 4
. Hence it will return 4
.
Now coming to your problem: define a struct
if any existing one doesn't help you, and return an object of struct instead, as:
struct values
{
int i;
int j;
char *other;
};
values f()
{
values v = {/*....*/};
//...
return v;
}
And if type of all values is same, then you can use std::vector
as:
#include <vector> //must include it!
std::vector<int> f()
{
std::vector<int> v;
v.push_back(5);
v.push_back(4);
//so on
//...
return v;
}
There are other containers as well, viz. std::map
, std::list
, std::stack
, etc. Use which suits you the best. There is also std::pair
which holds only two values, as the name implies.