The function total() is called with a count of the number of parameters in the first parameter numvalues, followed by the list of parameters defined by the ellipsis (...).
After setting temptotal to 0, the va_start macro is called with the variable values. This is of type va_list which has an internal parameter pointer set to point to the first parameter after numvalues.
Next the while loop counts from 4 down to 1. numvalues-- is a postdecremented expression which is true if numvalues is greater than 0. Immediately after evaluating this expression, numvalues is decremented.
If it had been written --numvalues, known as predecremented then numvalues would be decremented before the expression is evaluated. In this case when numvalues was 1 this expression would beeen false and the loop would only have run three times and missed the last value.
Inside the loop, the value of each successive parameter is added to temptotal and it switches its parameter pointer to the next parameter. The second parameter in the va_arg macro shows what type a parameter is expected to be. The arg in va_arg is short for argument, another name for parameter.
After the loop finishes, the va_end macro tidies up the values variable and the function return value is copied from the variable temptotal.
This concludes this lesson on functions.
In the next lesson Learn about Pointers.

