C Program to Return Multiple Values From a FunctionPooja
Method 1 : Using Array
- If more than two variables of same type is to be returned then we can use array .
- Store each and every value to be returned in an array and return base address of that array.
Method 2 : Using Pointer and One Return Statement
- Pointer Variable can updated directly using Value at [‘*’] Operator.
- Usually Function can return single value.
- If we need to return more than two variables then update 1 variable directly using pointer and return second variable using ‘return Statement‘. [ Call by Value + Call by Reference ]
Method 3 : Using Structure
- Construct a Structure containing values to be returned and then return the base address of the structure to the calling function.