how to return tow values in a modularised fountion? in c progam

来源:百度知道 编辑:UC知道 时间:2024/07/07 01:33:44
in c program.
we used to return a value to main fountion.
then how to return tow or more values to main fountion?
thanks a lot

use struct
for example , you want a fuction f return two values:a and b

struct returnTwo
{
int a;
int b;
};

struct returnTwo f()
{
struct returnTwo c
………………
c.a = 1;
c.b = 1;

return c
}

and get values in main by

struct returnTwo d;
d = f();

and now you can use them by
d.a and d.b

why not use a array?