A function call for a void function named calcEndingInventory() is passed four i
ID: 3812050 • Letter: A
Question
A function call for a void function named calcEndingInventory() is passed four int variables named beginInventory, sales, purchases, and endingInventory. The function’s task is to calculate the ending inventory, using the beginning inventory, sales, and purchase amounts passed to the function. The function should store the result in the endingInventoryvariable. Which of the following statements calls this function as described above?
a. calcEndingInventory(beginInventory, sales, purchases, endingInventory);
b. calcEndingInventory(int, int, int, int);
c. calcEndingInventory(beginInventory, sales, purchases, &endingInventory);
Explanation / Answer
Answer: c.
Since the function is a void function, it does not return any value.
To store or change the value of a variable in a void function, the variable must be passed a pointer.
Thus, in the function call,
calcEndingInventory(beginInventory, sales, purchases, &endingInventory);
the variable endingInventory is passed as a pointer so that the result could be stored in it in void function.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.