Quiz 5: Ch5 Functions

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Arissa_007
A
Arissa_007
Community Contributor
Quizzes Created: 1 | Total Attempts: 78
Questions: 10 | Attempts: 78

SettingsSettingsSettings
Quiz 5: Ch5 Functions - Quiz


Questions and Answers
  • 1. 

    Upload your response

  • 2. 

    What is the output for the segment of code shown below: 

    • A.

      B9

    • B.

      6

    • C.

      9

    • D.

      B

    Correct Answer
    A. B9
    Explanation
    The given segment of code is a sequence of characters. The output for this segment of code is the characters "B9" because it is the last line of the code.

    Rate this question:

  • 3. 

    Which of the following is FALSE about function ?

    • A.

      The formal parameters listed in a function header, must include each parameter’s data type and name.

    • B.

      The names of the formal parameters in the function header must be the same to the names of the actual arguments in the function call.

    • C.

      The sequence of parameters in the function call and parameters in the function header must be the same.

    • D.

      The function of a void function can be called in the numerical expression.

    Correct Answer
    D. The function of a void function can be called in the numerical expression.
    Explanation
    The function of a void function cannot be called in a numerical expression because a void function does not return a value. Void functions are used for performing actions or tasks without returning any value. They are typically used for tasks such as printing output, updating variables, or performing calculations without returning a result. Therefore, they cannot be used in numerical expressions where a value is expected to be returned.

    Rate this question:

  • 4. 

    Given the function prototype: void test (int, int, int&); Which of the following calling function statements is INVALID?

    • A.

      Test(2, 4, 5);

    • B.

      Test(x, y, z);

    • C.

      Test (d, 4, f);

    • D.

      Test (7, 14, c);

    Correct Answer
    A. Test(2, 4, 5);
    Explanation
    The function prototype for test() expects the third parameter to be of type int&, which means it should be a reference to an integer. In the calling function statement test(2, 4, 5), the third argument is a literal value 5, which cannot be passed as a reference. Hence, this calling function statement is invalid.

    Rate this question:

  • 5. 

    What is the return type for  the following function prototype ?char  FindCode(int, double,  float, char) ; 

    • A.

      Char

    • B.

      Int

    • C.

      Float

    • D.

      Double

    Correct Answer
    A. Char
    Explanation
    The return type for the given function prototype "FindCode" is char. This is indicated by the "char" keyword before the function name. The return type specifies the type of value that the function will return when it is called. In this case, the function is expected to return a value of type char.

    Rate this question:

  • 6. 

    The function prototype Example( ) is as given below:void Example (int x, int y, float z);Which of the following function call is VALID?

    • A.

      Example (int x, int y, float z);

    • B.

      Example (x, y, z);

    • C.

      A = Example (int x, int y, float z);

    • D.

      A = Example (x, y, z);

    Correct Answer
    B. Example (x, y, z);
    Explanation
    The function call "Example (x, y, z);" is valid because it matches the function prototype. The function prototype specifies that the function Example takes three arguments: an int, an int, and a float. In the given function call, the variables x, y, and z are being passed as arguments, which match the expected types. Therefore, this function call is valid.

    Rate this question:

  • 7. 

    Which of the following function prototypes with two integer parameters can be used for a void function named CalculateBalance?

    • A.

      Void CalculateBalance (int);

    • B.

      Int CalculateBalance (void);

    • C.

      Void CalculateBalance (int, int);

    • D.

      Int CalculateBalance (int, int);

    Correct Answer
    C. Void CalculateBalance (int, int);
    Explanation
    The correct answer is "void CalculateBalance (int, int)". This function prototype takes two integer parameters, which matches the requirement of the void function named CalculateBalance. The other function prototypes either have only one integer parameter or return an integer value, which do not fulfill the requirements.

    Rate this question:

  • 8. 

    What is the output for the following program?char testYou (int a, int& b, float c){   a = b * c;   b = a + c;   return 'K';}void main{   int x = 3;   int y = 4;   int z = 2;   char T = testYou (x,y,z);   cout<<x<<" "<<y<<" "<<z<<" "<<T;}

    • A.

      3 7 2 K

    • B.

      3 10 2 K

    • C.

      3 4 2 'K'

    • D.

      3 7 2 T

    Correct Answer
    B. 3 10 2 K
    Explanation
    The program defines a function called testYou that takes two integer parameters and one float parameter. Inside the function, the value of the first parameter (a) is updated by multiplying the second parameter (b) with the third parameter (c). Then, the value of the second parameter (b) is updated by adding the updated value of a and the value of c. The function returns the character 'K'.

    In the main function, three integer variables x, y, and z are initialized with the values 3, 4, and 2 respectively. The function testYou is called with these variables as arguments and the returned value is stored in the variable T. Finally, the values of x, y, z, and T are printed, resulting in the output "3 10 2 K".

    Rate this question:

  • 9. 

    What is the return type of the following function prototype?int function (char a, float v, double t);

    • A.

      Char

    • B.

      Int

    • C.

      Float

    • D.

      Double

    Correct Answer
    B. Int
    Explanation
    The return type of the given function prototype is int. This is indicated by the "int" keyword before the function name. It means that the function will return a value of type int after its execution is complete.

    Rate this question:

  • 10. 

    Given the following prototype:float test (int, int, int);Which of the following is VALID?

    • A.

      Cout

    • B.

      Cout

    • C.

      Cout

    • D.

      Cout

    Correct Answer
    D. Cout
    Explanation
    The given prototype declares a function named "test" that takes three integer parameters and returns a float value. The "cout" statements are unrelated to the prototype and are not valid in this context. The "cout" statement is used for outputting data to the console, while the prototype is used for declaring a function signature.

    Rate this question:

  • 11. 

    What is the output of the following program segment?void func (int &, int);void main( ){     int a = 10, b = 20;     func (a, b);     cout << a << " " <<b;}void func (int &x, int y){     x = x /3;     y = x;     cout << x << " " << y << endl;}

    • A.

      3 3 3 20

    • B.

      3 3 10 20

    • C.

      10 20 3 3

    • D.

      3 20 3 3

    Correct Answer
    A. 3 3 3 20
    Explanation
    The program segment defines a function called "func" that takes in two parameters, an integer reference "x" and an integer "y". In the main function, two integer variables "a" and "b" are declared and initialized with the values 10 and 20 respectively. Then, the "func" function is called with the variables "a" and "b" as arguments.

    Inside the "func" function, the value of "x" is divided by 3 and stored back into "x". Then, the value of "x" is assigned to "y". Finally, the values of "x" and "y" are printed.

    Since "a" is passed as a reference to "x" in the "func" function, any changes made to "x" will also affect the value of "a". Therefore, after the function call, the value of "a" becomes 3. However, "b" is passed by value to "y", so any changes made to "y" will not affect the value of "b". Therefore, the value of "b" remains 20.

    Hence, the output of the program segment is "3 3" followed by "3 20".

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Oct 06, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 30, 2015
    Quiz Created by
    Arissa_007
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.