C++ Programming Questions
C++ Programming Questions
1. Which of the following type of class allows only one object of it to be created?
A.
Virtual class
B.
Abstract class
C.
Singleton class
D.
Friend class
Copy constructor
B.
Friend constructor
C.
Default constructor
D.
Parameterized constructor
B.
C.
D.
Static function
B.
Friend function
C.
Const function
D.
Virtual function
5. Which of the following concepts means determining at runtime what method to invoke?
A.
Data hiding
B.
Dynamic Typing
C.
Dynamic binding
D.
Dynamic Loading
6. Which of the following term is used for a function defined inside a class?
A.
Member Variable
B.
Member function
C.
Class function
D.
Classic function
7. Which of the following concept of oops allows compiler to insert arguments in a function
call if it is not specified?
A.
Call by value
B.
Call by reference
C.
Default arguments
D.
Call by pointer
B.
C.
13
D.
Function
B.
Class
C.
Object
D.
Operator function
10. Which of the following concepts of OOPS means exposing only necessary information to
client?
A.
Encapsulation
B.
Abstraction
C.
Data hiding
D.
Data binding
B.
C.
D.
operator
B.
function
C.
object
D.
macro
13. Which of the following concepts provides facility of using object of one class inside another
class?
A.
Encapsulation
B.
Abstraction
C.
Composition
D.
Inheritance
B.
C.
D.
int
B.
double
C.
string
D.
Class
16. Which of the following concepts means adding new components to a program as it runs?
A.
Data hiding
B.
Dynamic typing
C.
Dynamic binding
D.
Dynamic loading
B.
C.
D.
Virtual polymorphism
B.
Transient polymorphism
C.
Ad-hoc polymorphism
D.
Pseudo polymorphism
Top-down
B.
Bottom-up
C.
Right-left
D.
Left-right
B.
C.
D.
Both A and B.
B.
class data members are public by default while that of structure are private.
C.
D.
class data members are private by default while that of structure are public by
default.
22. Which of the following concepts means wrapping up of data and functions together?
A.
Abstraction
B.
Encapsulation
C.
Inheritance
D.
Polymorphism
23. Which of the following concepts means waiting until runtime to determine which function to
call?
A.
Data hiding
B.
Dynamic casting
C.
Dynamic binding
D.
Dynamic loading
25.
A.
B.
C.
D.
>>
B.
<<
C.
D.
26. Which of the following is the correct class of the object cout?
A.
iostream
B.
istream
C.
ostream
D.
ifstream
27. Which of the following cannot be used with the keyword virtual?
A.
class
B.
member functions
C.
constructor
D.
destructor
B.
C.
D.
Initialize objects
B.
C.
A syntax error.
D.
A run-time error.
30. Which one of the following options is correct about the statement given below?
The compiler checks the type of reference in the object and not the type of object.
A.
Inheritance
B.
Polymorphism
C.
Abstraction
D.
Encapsulation
31. Which of the following is the correct way of declaring a function as constant?
A.
B.
C.
D.
Both A and B
Virtual function
B.
Operator function
C.
Const function
D.
Static function
B.
C.
D.
Both A and B.
34. Which of the following factors supports the statement that reusability is a desirable feature of
a language?
A.
B.
C.
D.
Both A and B.
35. Which of the following ways are legal to access a class data member using this pointer?
A.
this->x
B.
this.x
C.
*this.x
D.
*this-x
Operator overloading
B.
Function overloading
C.
Templates
D.
37. Which of the following is correct about the statements given below?
1. All operators can be overloaded in C++.
2. We can change the basic meaning of an operator in C++.
A.
Only I is true.
B.
C.
Only II is true.
D.
38. What happens if the base and derived class contains definition of a function with same
prototype?
A.
B.
C.
D.
Base class object will call base class function and derived class object will call
derived class function.
39. Which of the following are available only in the class hierarchy chain?
A.
B.
C.
D.
Member functions
Multiple
B.
Multilevel
C.
Distributive
D.
Hierarchical
[]
B.
->
C.
?:
D.
42. In which of the following a virtual call is resolved at the time of compilation?
A.
B.
C.
D.
Both A and B.
It speeds up execution.
B.
C.
D.
Both A and C.
44. Which one of the following is the correct way to declare a pure virtual function?
A.
B.
C.
D.
void Display(void) = 0;
45. Which of the following header file includes definition of cin and cout?
A.
istream.h
B.
ostream.h
C.
iomanip.h
D.
iostream.h
overload
B.
operator
C.
friend
D.
override
B.
C.
It is not allowed.
D.
Both A and B.
Multilevel inheritance
B.
Multiple inheritance
C.
Hybrid inheritance
D.
Hierarchical Inheritance
49. Which one of the following is correct about the statements given below?
1. All function calls are resolved at compile-time in Procedure Oriented Programming.
2. All function calls are resolved at compile-time in OOPS.
A.
Only II is correct.
B.
C.
Only I is correct.
D.
50. Which of the following is an invalid visibility label while inheriting a class?
A.
public
B.
private
C.
protected
D.
friend
B.
C.
D.
B.
C.
D.
B.
C.
D.
54. Which of the following access specifier is used as a default in a class definition?
A.
protected
B.
public
C.
private
D.
friend
A static member function can access only static data members of a class.
B.
A static data member is shared among all the object of the class.
C.
D.
Both A and B.
Abstraction
B.
Inheritance
C.
Dynamic binding
D.
Encapsulation
B.
C.
D.
B.
C.
It will not compile because a class cannot be protectedly inherited from other class.
D.
Friend keyword can be used in the class to allow access to another class.
B.
Friend keyword can be used for a function in the public section of a class.
C.
Friend keyword can be used for a function in the private section of a class.
D.
B.
C.
D.
4. Which of the following two entities (reading from Left to Right) can be connected by the dot
operator?
A.
B.
C.
D.
5.
B.
C.
D.
B.
C.
D.
B.
C.
D.
by default?
A.
Protected
B.
Public
C.
Private
D.
Friend
B.
C.
D.
11.
A.
Default
B.
Break
C.
Protected
D.
Asm
Which of the following can access private data members or member functions of a class?
A.
B.
C.
D.
12. Which of the following type of data member can be shared by all instances of its class?
A.
Public
B.
Inherited
C.
Static
D.
Friend
Friend Functions
B.
Object
C.
Member Functions
D.
Member Variables
an object is created
B.
an object is used
C.
a class is declared
D.
15. Which of the following statements about virtual base classes is correct?
A.
B.
C.
D.
It allows private members of the base class to be inherited in the derived class.
Zero
B.
One
C.
Two
D.
As many as we want
};
class Engine
{
float CC;
};
A.
kind of relationship
B.
has a relationship
C.
Inheritance
D.
Both A and B
18. Which of the following statements is correct when a class is inherited privately?
A.
Public members of the base class become protected members of derived class.
B.
Public members of the base class become private members of derived class.
C.
Private members of the base class become private members of derived class.
D.
Public members of the base class become public members of derived class.
B.
C.
D.
It shows the relationships between the classes in the form of an organization chart.
B.
C.
D.
Object
B.
Functions
C.
Operators
22. Which of the following means "The use of an object of one class in definition of another
class"?
A.
Encapsulation
B.
Inheritance
C.
Composition
D.
Abstraction
23. Which of the following is the only technical difference between structures and classes in
C++?
A.
Member function and data are by default protected in structures but private in
classes.
B.
Member function and data are by default private in structures but public in classes.
C.
Member function and data are by default public in structures but private in classes.
D.
Member function and data are by default public in structures but protected in
classes.
24. Which of the following statements is correct about the program given below?
class Bix
{
public:
static void MyFunction();
};
int main()
{
void(*ptr)() = &Bix::MyFunction;
return 0;
}
A.
B.
C.
D.
25. Which of the following statements are correct for a static member function?
1. It can access only other static members of its class.
2. It can be called using the class name, instead of objects.
A.
Only 1 is correct.
B.
Only 2 is correct.
C.
D.
Functions
1. Which of the following function prototype is perfectly acceptable?
A.
B.
C.
Both A and B.
D.
B.
We cannot change the argument of the function that that are declared as constant.
C.
Both A and B.
D.
B.
C.
D.
Two functions having same number of argument, order and type of argument can
be overloaded if both functions do not have any default argument.
B.
C.
Overloaded function must have default arguments starting from the left of
argument list.
D.
5. Which of the following statement will be correct if the function has three arguments passed
to it?
A.
B.
C.
D.
B.
C.
D.
B.
C.
D.
Member function
B.
Static function
C.
Virtual function
D.
Both B and C
B.
C.
D.
E.
B.
C.
Compiler uses the prototype information to build a call, not the function definition.
D.
The default arguments are given in the function prototype and should be repeated
in the function definition.
Function call
B.
Function definition
C.
Function prototype
D.
Both B or C
B.
C.
Both A and B.
D.
B.
C.
D.
A default argument is checked for type at the time of declaration and evaluated at
the time of call.
B.
C.
D.
Default arguments are useful in situations where some arguments always have the
same value.
B.
C.
Overloaded functions can accept only same number and same type of arguments.
D.
Overloaded functions can accept only different number and different type of
arguments.
16. Which of the following function / types of function cannot have default parameters?
A.
B.
main()
C.
D.
Both B and C
B.
C.
D.
one
B.
two
C.
no
D.
three
2. What happens when a class with parameterized constructors and having no default
constructor is used in a program and we create an object that needs a zero-argument
constructor?
A.
Compile-time error.
B.
Preprocessing error.
C.
Runtime error.
D.
Runtime exception.
Yes
B.
No
4. Destructor has the same name as the constructor and it is preceded by ______ .
A.
B.
C.
D.
5. For automatic objects, constructors and destructors are called each time the objects
A.
B.
C.
are constructed
D.
are destroyed
6. Which constructor function is designed to copy objects of the same class type?
A.
Create constructor
B.
Object constructor
C.
Dynamic constructor
D.
Copy constructor
B.
Destructor has the same name as that of the class with a tilde symbol at the
beginning.
C.
Both A and B.
D.
Destructor has the same name as the first member function of the class.
B.
C.
D.
Both B and C.
When the control comes out of the block in which they are being used.
B.
C.
When the control comes out of the function in which they are being used.
D.
B.
only pass-by-value
C.
only pass-by-reference
D.
11. A function with the same name as the class, but preceded with a tilde character (~) is called
__________ of that class.
A.
constructor
B.
destructor
C.
function
D.
object
12. A union that has no constructor can be initialized with another union of __________ type.
A.
different
B.
same
C.
virtual
D.
class
13. Which of the following gets called when an object goes out of scope?
A.
constructor
B.
destructor
C.
main
D.
virtual function
15.
A.
B.
C.
D.
A.
constructor
B.
copy constructor
C.
destructor
D.
default constructor
cannot overloaded
B.
can be overloaded
C.
can be called
D.
can be nested
B.
C.
D.
Constructor
B.
Destructor
C.
Data Members
D.
Both A and C
19. If the copy constructor receives its arguments by value, the copy
constructor would
A.
B.
C.
D.
Zero-argument Constructor
B.
Destructor
C.
Copy Constructor
D.
Copy Destructor
21.
logical
B.
virtual
C.
syntax
D.
linker
22. If the programmer does not explicitly provide a destructor, then which of the following
creates an empty destructor?
A.
Preprocessor
B.
Compiler
C.
Linker
D.
main() function
23. A __________ is a constructor that either has no parameters, or if it has parameters, all the
parameters have default values.
A.
default constructor
B.
copy constructor
C.
Both A and B
D.
None of these
Only one
B.
Two
C.
Three
D.
Unlimited
B.
C.
D.
B.
C.
D.
27. Which of the following implicitly creates a default constructor when the programmer does
not explicitly define at least one constructor for a class?
A.
Preprocessor
B.
Linker
C.
Loader
D.
Compiler
one
B.
two
C.
three
D.
no
29. Destructor calls are made in which order of the corresponding constructor calls?
A.
Reverse order
B.
Forward order
C.
D.
30.
Member function
B.
Friend function
C.
Default constructor
D.
const functio
constructor
B.
destructor
C.
assignment function
D.
copy constructor
are called
B.
are inherited
C.
D.
are created
B.
C.
D.
Both A and B.
B.
C.
D.
Only once
B.
Twice
C.
Thrice
D.
36.
constructor
B.
virtual function
C.
destructor
D.
main
37. To ensure that every object in the array receives a destructor call, always
delete memoryallocated as an array with operator __________ .
A.
destructor
B.
delete
C.
delete[]
D.
kill[]
E.
free[]
B.
C.
D.
39. Which of the following statement is correct whenever an object goes out of scope?
A.
B.
C.
D.
References
1. Which of the following statement is correct?
A.
B.
C.
D.
Only 1 is correct.
B.
Only 2 is correct.
C.
D.
3. Functions can be declared to return a reference type. There are reasons to make such a
declaration/Which of the following reasons are correct?
1. The information being returned is a large enough object that returning a reference
is more efficient than returning a copy.
2. The type of the function must be a R-value.
A.
Only 1 is correct.
B.
Only 2 is correct.
C.
D.
Only 1 is correct.
B.
Only 2 is correct.
C.
D.
B.
C.
D.
Both A and C.
&&
B.
&
C.
||
D.
Once a reference variable has been defined to refer to a particular variable it can
refer to any other variable.
B.
C.
D.
Only 1 is correct.
B.
Only 2 is correct.
C.
D.
Only 1 is correct.
B.
Only 2 is correct.
C.
D.
B.
C.
D.
Only 1 is correct.
B.
Only 2 is correct.
C.
D.
Only 1 is correct.
B.
Only 2 is correct.
C.
D.
Pointer
B.
Structure
C.
Macro
D.
Enum
B.
C.
D.
B.
Once a reference variable has been defined to refer to a particular variable it can
refer to any other variable.
C.
D.
B.
Once a reference variable has been defined to refer to a particular variable it can
refer to any other variable.
C.
D.
Only 1 is correct.
B.
Only 2 is correct.
C.
D.