Quiz: Functions

To View Tricks: Login Required

Number of Questions: 25

Question: 16 -

In which of the following cases inline functions may not word?

i) If the function has static variables.
ii) If the function has global and register variables.
iii) If the function contains loops
iv) If the function is recursive

Options:
  1. i, iii, iv

  2. ii, iii, iv

  3. iii, iv

  4. i, iv

  5. Answer:

    i, iii, iv

    Solution:

    A function is not inline if it has static variables, loops or the function is having any recursive calls.


Question: 17 -

Where should default parameters appear in a function prototype?

Options:
  1. To the rightmost side of the parameter list

  2. Anywhere inside the parameter list

  3. To the leftmost side of the parameter list

  4. Middle of the parameter list

  5. Answer:

    To the rightmost side of the parameter list

    Solution:

    Default parameters are defined to the rightmost side of parameter list in a function to differentiate between the normal and default parameters for example if a function is defined as fun(int x = 5, int y) then if we call fun(10) then 10 should be given to x or y because one can apply both logics like x = 10 already defined and 10 passed is for y but if compiler reads it from left to right it will think it is for x and no parameter is given for y, therefore, the compiler will give error.


Question: 18 -

When we define the default values for a function?

Options:
  1. When the scope of the function is over

  2. When a function is defined

  3. When a function is called

  4. When a function is declared

  5. Answer:

    When a function is declared

    Solution:

    Default values for a function is defined when the function is declared inside a program.


Question: 19 -

An inline function is expanded during ______________

Options:
  1. end of the program

  2. compile-time

  3. run-time

  4. never expanded

  5. Answer:

    compile-time

    Solution:

    An inline function is expanded during the compile-time of a program.


Question: 20 -

What is an inline function?

Options:
  1. A function that is not checked for syntax errors

  2. A function that is not checked for semantic analysis

  3. A function that is called during compile time

  4. A function that is expanded at each call during execution

  5. Answer:

    A function that is expanded at each call during execution

    Solution:

    Inline function is those which are expanded at each call during the execution of the program to reduce the cost of jumping during execution.