Loading...

C++ Multiple Choice Questions

Our C++ questions and answers focuses on all areas of C++ programming language covering 100+ topics in C++

C++ Functions MCQ | Set 2

C++ Functions | Set 2


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

a) It becomes a virtual function of the class
b) It becomes a default calling function of the class
c) It becomes an inline function of the class
d) The program gives an error



12. What is an inline function?

a) A function that is expanded at each call during execution
b) A function that is called during compile time
c) A function that is not checked for syntax errors
d) A function that is not checked for semantic analysis



13. An inline function is expanded during ______________

a) compile-time
b) run-time
c) never expanded
d) end of the program



14. 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
a) i, iv
b) iii, iv
c) ii, iii, iv
d) i, iii, iv



15. When we define the default values for a function?

a) When a function is defined
b) When a function is declared
c) When the scope of the function is over
d) When a function is called



16. Where should default parameters appear in a function prototype?

a) To the rightmost side of the parameter list
b) To the leftmost side of the parameter list
c) Anywhere inside the parameter list
d) Middle of the parameter list



17. If an argument from the parameter list of a function is defined constant then _______________

a) It can be modified inside the function
b) It cannot be modified inside the function
c) Error occurs
d) Segmentation fault



18. Which of the following feature is used in function overloading and function with default argument?

a) Encapsulation
b) Polymorphism
c) Abstraction
d) Modularity



19. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int fun(int x = 0, int y = 0, int z){
    return (x + y + z);
}
int main() {

    cout << fun(10);
    
    return 0;
}

a) 10
b) 0
c) Error
d) Segmentation fault



20. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int fun(int = 0, int = 0);
int main() {

    cout << fun(5);
    return 0;
}
int fun(int x, int y){
    return (x + y);
}

a) -5
b) 0
c) 10
d) 5



- Related Topics