Return multiple values from a function in C.
In C function return only one value. Like below function return only one int value.
int fun(int a , int b) //return one int value.
To return multiple values, we have to use struct/pointer.
eg:
struct Values {
int a;
int b ;
};
typedef struct Values values;
values fun(int x ,int y) {
values vals ;
vals.a = x;
vals.b = y ;
return vals;
}
If we want the function to return multiple values of same data types, we could return the pointer to array of that data types.
Written by ranjeet kumar
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Tips
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#