Question: 16 -
i) If the function has static variables.In which of the following cases inline functions may not word?
ii) If the function has global and register variables.
iii) If the function contains loops
iv) If the function is recursive
-
i, iii, iv
-
ii, iii, iv
-
iii, iv
-
i, iv
Answer:
i, iii, iv
Solution:
A function is not inline if it has static variables, loops or the function is having any recursive calls.
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?
-
To the rightmost side of the parameter list
-
Anywhere inside the parameter list
-
To the leftmost side of the parameter list
-
Middle of the parameter list
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.
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?
-
When the scope of the function is over
-
When a function is defined
-
When a function is called
-
When a function is declared
Answer:
When a function is declared
Solution:
Default values for a function is defined when the function is declared inside a program.
Default values for a function is defined when the function is declared inside a program.
Question: 19 -
An inline function is expanded during ______________
-
end of the program
-
compile-time
-
run-time
-
never expanded
Answer:
compile-time
Solution:
An inline function is expanded during the compile-time of a program.
An inline function is expanded during the compile-time of a program.
Question: 20 -
What is an inline function?
-
A function that is not checked for syntax errors
-
A function that is not checked for semantic analysis
-
A function that is called during compile time
-
A function that is expanded at each call during execution
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.
Inline function is those which are expanded at each call during the execution of the program to reduce the cost of jumping during execution.