Quiz: Functions

To View Tricks: Login Required

Number of Questions: 25

Question: 11 -

What happens to a function defined inside a class without any complex operations (like looping, a large number of lines, etc)?

Options:
  1. It becomes a virtual function of the class

  2. It becomes an inline function of the class

  3. It becomes a default calling function of the class

  4. The program gives an error

  5. Answer:

    It becomes an inline function of the class

    Solution:

    Any function which is defined inside a class and has no complex operations like loops, a large number of lines then it is made inline.


Question: 12 -

How many minimum number of functions should be present in a C++ program for its execution?

Options:
  1. 1

  2. 0

  3. 3

  4. 2

  5. Answer:

    1

    Solution:

    The execution of a C++ program starts from main function hence we require atleast 1 function to be present in a C++ program to execute and i.e. the main function.


Question: 13 -

What is the scope of the variable declared in the user defined function?

Options:
  1. the main function

  2. whole program

  3. only inside the {} block

  4. header section

  5. Answer:

    only inside the {} block

    Solution:

    The variable is valid only in the function block as in other.


Question: 14 -

Which of the following is the default return value of functions in C++?

Options:
  1. int

  2. void

  3. char

  4. float

  5. Answer:

    int

    Solution:

    C++ uses int as the default return values for functions. It also restricts that the return type of the main function must be int.


Question: 15 -

What will be the output of the following C++ code?

#include <iostream>
using namespace std;
void fun(int x, int y){
    x = 20;
    y = 10;
}
int main() {

    int x = 10;
    fun (x, x);
    cout << x;
    
    return 0;
}

Options:
  1. Error

  2. 20

  3. 30

  4. 10

  5. Answer:

    10

    Solution:

    In this program, we called by value so the value will not be changed, So the output is 10