Comparison of integers between void functions

This is course work, and pre-provided code which I am struggling to understand:; the following code has a number of functions, only one of which I counted have a return value. None the less, they set values of an integer array, but seemingly do nothing with them. How do the values determined in these void functions get passed around?

For example, sortArray function sets the values of a list[] to be ordered, but it isn't a pointer or anything and it doesn't return an array, so I don't know how I can use that data in other functions like the comparison between user number and that sorted list?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime> 

using namespace std;

const int ARRAY_SIZE = 5;

inline void initializeList(int list[])
{
    for (int index = 0; index < ARRAY_SIZE; index++)
        list[index] = -1;
}

inline bool numInList(int list[], int num)
{
    for (int index = 0; index < 5; index++)
        if (list[index] == num)
            return true;
    return false;
}

// part a
inline void getLottoNum(int list[])
{
    // set the items in "list" to random numbers between 1 and 40, inclusive
}


// part b
inline void sortLottoNum(int list[])
{
    // sort the array containing the lottery numbers
}

inline void getCustNum(int list[])
{
    // prompts the player to select 5 distinct numbers between 1 and 40, inclusive

    // ensure that the numbers are between 1 and 40, inclusive

    // store the numbers in "list"
}

// part d
inline bool checkLottoNum(int list1[], int list2[])
{
    // determine if the user has guessed all 5 numbers correctly
}

inline void printList(int list[])
{
    for (int i = 0; i < ARRAY_SIZE; i++)
        cout << list[i] << "  ";
    cout << endl;
}
"return" is not the only way to return data from a function.
In your case, list, list1, list2 are passed as c-style arrays, which means that in the functions they become pointers to the first element of the array in the functions. That means that you can modify the caller's array through those pointers (usually using array notation).
Topic archived. No new replies allowed.