prasad2315
asked on
how to return multiple values from a function
how to return multiple values from a function
You can return a struct
A function can only return one entity. The simplest way handle multiple values to have in/out parameters. In the example below I pass 2 int types to a function by pointer, they are modified in that function and the changes are visible outside of the function.
#include <stdio.h>
void foo(int * p1, int * p2)
{
*p1 = 9;
*p2 = 3;
}
int main(int argc, char* argv[])
{
int i1, i2;
foo(&i1, &i2);
printf("%d %d", i1, i2);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you can also set global variables, or some cases encode multiple values into a single value