Test Series - cpp

Test Number 8/102

Q: Why this pointer is used?
A. To access the members of a class which have the same name as local variables in that scope
B. To access all the data stored under that class
C. To access objects of other class
D. To access objects of other variables
Solution: this pointer is used to access the members of a class which have the same name as local variables in that part of the code.
Q: How many types of polymorphism are there?
A. 1
B. 2
C. 3
D. 4
Solution: There are two types of polymorphism in C++ namely compile-time polymorphism and run-time polymorphism.
Q: What is the other name of compile-time polymorphism?
A. Static polymorphism
B. Dynamic polymorphism
C. Executing polymorphism
D. Non-executing polymorphism
Solution: Compile-time polymorphism is also known as static polymorphism as it is implemented during the compile-time.
Q: What is the other name of run-time polymorphism?
A. Static polymorphism
B. Dynamic polymorphism
C. Executing polymorphism
D. Non-executing polymorphism
Solution: Run-time polymorphism is also known as dynamic polymorphism as it is implemented during the run-time of the program.
Q: Which of the following is correct about static polymorphism?
A. In static polymorphism, the conflict between the function call is resolved during the compile time
B. In static polymorphism, the conflict between the function call is resolved during the run time
C. In static polymorphism, the conflict between the function call is never resolved during the execution of a program
D. In static polymorphism, the conflict between the function call is resolved only if it required
Solution: The conflict between which function to call is resolved during the compile time in static polymorphism i.e. before the execution of the program starts.
Q: Which of the following is correct about dynamic polymorphism?
A. In dynamic polymorphism, the conflict between the function call is resolved during the compile time
B. In dynamic polymorphism, the conflict between the function call is resolved during the run time
C. In dynamic polymorphism, the conflict between the function call is never resolved during the execution of the program
D. In dynamic polymorphism, the conflict between the function call is resolved at the beginning of the program
Solution: The conflict between which function to call is resolved during the run time in dynamic polymorphism i.e. the conflict is resolved when the execution reaches the function call statement.
Q: Which of the following operator(s) can be used with pointers?
i) – only
ii) +, *
iii) +, –
iv) +, -, *
v) /
vi) + only
A. i only
B. vi only
C. ii and v
D. iv
Solution: The only arithmetic operator that can be used with a pointer is – subtraction operator. No arithmetic operator can be used with pointers.
Q: What is std in C++?
A. std is a standard class in C++
B. std is a standard namespace in C++
C. std is a standard header file in C++
D. std is a standard file reading header in C++
Solution: std is a standard namespace present in C++ which contains different stream classes and objects like cin, cout, etc. and other standard functions.
Q: What will be the output of the following C++ code?

#include 
 
int main(int argc, char const *argv[])
{
	cout<<"Hello World";
	return 0;
}
A. Hello World
B. Compile-time error
C. Run-time error
D. Segmentation fault
Solution: cout is defined under the namespace std and without including std namespace we cannot cout, therefore, the program gives an error.
Q: Which of the following syntax can be used to use a member of a namespace without including that namespace?
A. namespace::member
B. namespace->member
C. namespace.member
D. namespace~member
Solution: To use a member of a namespace without including the namespace is done by this syntax namespace::member.

You Have Score    /10