How we can return multiple values from a function?
Multiple Return
Collapse
X
-
Tags: None
-
Originally posted by Azaz ul haqHow we can return multiple values from a function?
You can do this by passing the parameters which will be modified by the function with the values.
This logic is there in C# where you specify the parameter is typw IN or type OUT
Raghuram -
With pointers.
You make a function argument to be the pointer to the type and once the function is called actually the passed parameter will have the value modified from inside the function.(in c,in c++ you can use references)
e.g
[CODE=c]void Increase(int *pInt)
{
(*pInt)++;
}
//test call
int k=5;
Increase(&k);//k becomes 6;[/CODE]
More pointers you put as function arguments,more values you can return from the function+1 if you have a return type other then a void.
SavageComment
Comment