30.8k views
0 votes
A program contains the following function definition: int cube(int number) { return number * number * number; } Write a statement that calls this function, passing the value 4 as an argument, and assigns the function's return value to the variable result.

1 Answer

6 votes

Answer:

The statement can be written as

int result = cube(4);

Step-by-step explanation:

A function is a block of reusable codes to perform some tasks. For example, the function in the question is to calculate the cube of a number.

A function can also operate on one or more input value (argument) and return a result. The cube function in the question accept one input value through its parameter number and the number will be multiplied by itself twice and return the result.

To call a function, just simply write the function name followed with parenthesis (e.g. cube()). Within the parenthesis, we can include zero or one or more than one values as argument(s) (e.g. cube(4)).

We can then use the "=" operator to assign the return output of the function to a variable (e.g. int result = cube(4))