Thread: Make an array the same as an array from a function

1. Make an array the same as an array from a function

Hey,
I have a function that returns an array that contains all the digits of a number
Code:
```int seperation(int number){
int arrayOfDigits[SIZE];
int i = SIZE - 1;
int lastDigit;
while(number!=0){
lastDigit = number % 10;
arrayOfDigits[i] = lastDigit;
i--;
number /= 10;
}
return(arrayOfDigits);```
If i want to make an array that I have in my main function to be the same as the arrayOfDigits that is in this function what do i have to do?

2. The simplest thing to do is
Code:
```void seperation(int number, arrayOfDigits[SIZE]){
int i = SIZE - 1;
int lastDigit;
while(number!=0){
lastDigit = number % 10;
arrayOfDigits[i] = lastDigit;
i--;
number /= 10;
}
}```
That is, you pass in the array of where you want the result to be stored.

This gives the caller the best opportunity to decide where to store the result, and saves all the complication that the called function would have to deal with when trying to return an array.