99.6k views
3 votes
Given the following function prototype:

int test (float, char);

which of the following statements is valid?
a. cout << test(12, &);
b. cout << test("12.0", '&');
c. int u = test(5.0, '*');
a. cout << test('12', '&');

2 Answers

4 votes

Final answer:

The valid statement for the function prototype 'int test (float, char);' is 'int u = test(5.0, '*');'. This is because it correctly provides a float and a char, consistent with the function's expected input types.

Step-by-step explanation:

The function prototype int test (float, char); indicates that the function named test takes a float and a char as its parameters and returns an int. Given the prototype, let's examine the validity of each statement:

a. cout << test(12, '&'); - This call is invalid because the first argument is an int, not a float. An int can be implicitly converted to a float, but it's important to note the subtle difference.

b. cout << test("12.0", '&'); - This call is invalid because the first argument is a string literal, whereas the function expects a float.

c. int u = test(5.0, '*'); - This statement is valid. It correctly supplies a float and a char to the function, which matches the function's expected parameters.

a. cout << test('12', '&'); - This statement is invalid because '12' is a multi-character constant and not a single char.

User Pbristow
by
7.6k points
0 votes

Final answer:

The correct statement that calls the function 'int test(float, char)' validly is 'int u = test(5.0, '*');' because it follows the required float and char parameters.

Step-by-step explanation:

The question asks us to determine which statement is valid when calling a function with the prototype int test(float, char). This function requires a float as the first argument and a char as the second argument.

Let's evaluate each option provided:

  1. cout << test(12, '&'); - This is not valid because 12 is an integer, not a float.
  2. cout << test("12.0", '&'); - This is not valid because "12.0" is a string literal, not a float.
  3. int u = test(5.0, '*'); - This is a valid statement because 5.0 is a float and '*' is a char.
  4. cout << test('12', '&'); - This is not valid because '12' is a multi-character constant, not a single char.

The correct answer is the third option: int u = test(5.0, '*'); because it provides the proper float and char as required by the function prototype.

User Gorazd Rebolj
by
6.9k points