# Function returning more than one value?

This is a discussion on Function returning more than one value? within the C Programming forums, part of the General Programming Boards category; Hi, Is it possible for a single function to return more than one value? Code: void Prompt(void) { double households[SIZE], ...

1. ## Function returning more than one value?

Hi,
Is it possible for a single function to return more than one value?

Code:
```void Prompt(void)

{
double households[SIZE],
average=0,
maximum,
minimum,
input;

int	   incomes;

printf("\nPlease enter the families income.\n");

for(incomes=0; incomes<SIZE; ++incomes)
{
printf("\nFamily (%d): " , incomes+1);
scanf("%lf" , &input);
average += maximum = minimum = input;
households[incomes] = input;
}

return maximum;
return minimum;     /*like this*/
return average;
}```
If so, how would the returns be coded in main()?

2. Pointers are your friends...
Code:
```#include <stdio.h>

int foobar (int *n)
{
*n = 10;
return 5;
}

int main(void)
{
int a;
int b;

a = foobar(&b);

printf("a: %d\nb: %d\n", a, b);
return 0;
}```

3. Unfortunately I don't know pointers yet. So I guess a function alone can't do it?

4. I gave you a very simple example: understand and use it.

The answer to your question is no.

5. Define a structure and use that to return the values.

6. Don't know how to do that yet either.

7. then learn it...

Popular pages Recent additions