C++ MCQ - qb
C++ MCQ - qb
1. What is C++?
a) C++ is an object oriented programming language
b) C++ is a procedural programming language
c) C++ supports both procedural and object oriented programming language
d) C++ is a functional programming language
Answer: c
Explanation: C++ supports both procedural(step by step instruction) and object oriented
programming (using the concept of classes and objects).
4.By default, all the files in C++ are opened in _________ mode.
a) Binary
b) VTC
c) Text
d) ISCII
Answer: c
Explanation: By default, all the files in C++ are opened in text mode. They read the file as
normal text.
5.Which of the following is the correct syntax to add the header file in the C++ program?
1. #include "userdefined.h"
2. #include <userdefined.h>
3. <include> "userdefined.h"
4. Both A & B
Answer: Both A & B
7.Which of the following is the correct syntax to print the message in C++ language?
1. Out <<"Hello world!;
2. cout <<"Hello world!";
3. Cout << Hello world! ;
4. None of the above
Answer: cout <<"Hello world!";
8.Which of the following can be considered as the correct syntax for declaring an array of
pointers of integers that has a size of 10 in C++?
1. int *arr = new int*[10]
2. int *arr = new int[10];
3. int arr = new int[10];
4. int **arr = new int*[10];
Answer: int **arr = new int*[10];
9.Which of the following is the correct syntax for printing the address of the first element?
1. array[0];
2. array[2];
3. array[1];
4. None of the above
Answer: array[0];
12. The programming language that has the ability to create new data types is
called_______________
1. Overloaded
2. Reprehensible
3. Extensible
4. Encapsulated Answer: Extensible
14.Which of the following features must be supported by any programming language to become
a pure object-oriented programming language?
1. Inheritance
2. Encapsulation
3. Polymorphism
4. All of the above
Answer: All of the above
17. Which of the following is the correct syntax to read the single character to console in the
C++ language?
1. get(ch)
2. Scanf(ch)
3. Read ch()
4. Getline vh()
Answer: get(ch)
18.For inserting a new line in C++ program, which one of the following statements can be used?
1. \r
2. \n
3. endl
4. both 2 and 3
Answer: both 2 and 3
20. Which of the following is used to terminate the function declaration in C++?
a) ;
b) ]
c) )
d) :
Answer: a
Explanation: ; semicolon is used to terminate a function declaration statement in C++.
a) 323334
b) 323232
c) 323130
d) 323134
Answer: a
Explanation: If we not assigned any value to enum variable means, then the next number to
initialized number will be allocated to the variable.
28. What is operator overloading in C++?
a) Overriding the operator meaning by the user defined meaning for user defined data type
b) Redefining the way operator works for user defined types
c) Ability to provide the operators with some special meaning for user defined data type
d) All of the mentioned
Answer: d
Explanation: Operator overloading helps programmer to give his/her own meaning to an operator
for user defined data types(eg, classes).
38.Which of the following is not a fundamental type is not present in C but present in C++?
a) int
b) float
c) bool
d) void
Answer: C
50. The function that can access and manipulate the private entities of class
a. Abstract class b. Method class c. User defined class d. Friend function
And d. Friend function
54. Destructor is the member function whose name as the class name but is preceded by a ____
a. hash b. dot. c. dollor d. tilde
60. The C++ header file ……………….. contains function prototypes for the standard input and
standard output functions.
A) <iomanip>
B) <fstream>
C) <iostream>
D) <cstdio>
Ans:C) <iostream>
61. The binding of data and functions together into a single class-type variable is referred to as
…………..
A) encapsulation
B)Polymorphism
C)inheriatnce
D)overloading
Ans: A) encapsulation
62. Which of the following statements about member functions are True or False.
i) A member function can call another member function directly with using the dot operator.
ii) A member function can access the private data of the class.
A) i-True, ii-True
B) i-False, ii-True
C) i-True, ii-False
D) i-True, ii-True
Ans:B) i-False, ii-True
63. …………………. refer to the names of variables, functions, arrays, classes etc. created by
the
programmer.
A) Keywords
B) Identifiers
C) Constants
D) Strings
Ans: B) Identifiers
64………………….. are explicitly reserved identifiers and cannot be used as names for the
program variables or other user-defined program elements.
A) Keywords
B) Identifiers
C) Constants
D) Strings
Ans: A) Keywords
65. State whether the following statements are True or False for C++ identifiers.
i) Only alphabetic characters, digits and underscores are permitted.
ii) The name can start with a digit.
iii) Uppercase and lowercase letters are distinct.
A) i-True, ii-True, iii-False
B) i-True, ii-False, iii-True
C) i-True, ii-False, iii-False
D) i-True, ii-True, iii-True
Ans: . B) i-True, ii-False, iii-True
66. In C++, ………………….. refer to fixed values that do not change during the execution of a
program.
A) Identifiers
B) Constants
C) Strings
D) Operators
Ans: B) Constants
67. Which of the following is NOT the user-defined data type in C++ .
A) Structure
B) Pointer
C) Union
68. Which of the following is NOT the user-defined data type in C++ .
A) Structure
B) Pointer
C) Union
D) Class
Ans:B) Pointer
69. Which of the following is/are the derived data types in C++.
i) array ii) function iii) pointer iv) class
A) i, ii and iii only
B) ii, iii and iv only
C) i, iii and iv only
D) All i, ii, iii and iv
Ans: 10. A) i, ii and iii only
70. We can create …………………….. in C++ using the qualifier constant and defining a set of
integer constant using enum keywords.
A) basic constant
B) number constant
C) symbolic constant
D) named constant
Ans:C) symbolic constant
71. C++ permits initialization of the variables at run time which is referred to as ……………….
initialization.
A) static
B) dynamic
C) variable
D) runtime
Ans: B) dynamic
72. Which of the following is the scope resolution operator in C++.
A) : :
B) : : *
C) _>*
D) . *
Ans: A) : :
74. The …………….. manipulator is used in an output statement which causes a linefeed to be
inserted.
A) setw
B) delete
C) endl
D) symbol
C) endl
76.…………………. produce results of type bool which takes a value true or false.
A) Relational expressions
B) Float expressions
C) Logical expressions
D) Bitwise expressions
Ans: A) Relational expressions
77.…………… combine to or more relational expressions and produces bool type results.
A) Relational expressions
B) Float expressions
C) Logical expressions
D) Bitwise expressions
Ans: C) Logical expressions
83. Constructors cannot be inherited, through a derived class can call the ……………….
constructor.
A) base class
B) derived class
C) void class
D) default class
Ans:A) base class
84. State whether the following statements about the constructor are True or False.
i) constructors should be declared in the private section.
ii) constructors are invoked automatically when the objects are created.
A) True, True
B) True, False
C) False, True
D) False, False
Ans:C) False, True
85. Destructor is a member function whose name is same as the class name but is preceded by a
………..
A) tilde
B) hash
C) dot
D) dollor
Ans:A) tilde
86. A destructor is used to destroy the objects that have been created by a ………………..
A) objects at the run time
B) destructor class
C) function
D) constructor
Ans:D) constructor
88. The ……………. inherits some or all of the properties of the ……….. class.
A) base, derived
B) derived, base
C) derived, initial
D) base, final
ANSWER B) derived, base
89.A derived class with only one base class is called …………… inheritance.
A) single
B) multiple
C) multilevel
D) hierarchical
ANSWER A) single
90. A class can inherit properties from more than one class which is known as
……….inheritance.
A) single
B) multiple
C) multilevel
D) hierarchical
ANSWER B) multiple
91. A class can be derived from another derived class which is known as ………. inheritance.
A) single
B) multiple
C) multilevel
D) hierarchical
ANSWER C) multilevel
92. When the properties of one class are inherited by more than one class, which is called
………
inheritance.
A) single
B) multiple
C) multilevel
D) hierarchical
ANSWER D) hierarchical
93. When a base class is privately inherited by a derived class public members of the base class
become ………. of the derived class.
A) private members
B) protected members
C) Public members
D) Not inherited
ANSWER A) private members
94. When a base class is privately inherited by derived class public members of the base class
canonly be accessed by the ……… of the derived class.
A) non-member functions
B) friend functions
C) member functions
D) class members
ANSWER C) member functions
95. When a protected member is inherited in public mode, it becomes ……….. in the derived
class too and therefore is accessible by member functions of the derived class.
A) protected
B) private
C) public
D) friend
ANSWER A) protected
96.State whether the following statements about inheritance are True or False.
i) A public member of a class can be accessed by its own objects using the dot operator.
ii) While inheriting, the private members of the base class will never become members of its
derived class.
A) True, False
B) False, True
C) True, True
D) False, False
ANSWER C) True, True
97. A member declared as ………….. is accessible by the member functions within its class and
any
class immediately derived from it.
A) protected
B) private
C) public
D) friend
ANSWER A) protected
98.When the base class is publicly inherited, public members of the base class become
………….
of the derived class.
A) private members
B) protected members
C) Public members
D) Not inherited
ANSWER C) Public members
99. In the protected derivation, both the public and protected members of the base class become
…………. members of the derived class.
A) protected
B) private
C) public
D) friend
ANSWER A) protected
100. What will be the order of execution of base class constructors in the following method of
inheritance?
class A: public B, public C {….};
A) B(); C(); A();
B) C(); B(); A();
C) A(); B(); C();
D) B(); A(); C();
ANSWER A) B(); C(); A();
101.What will be the order of execution of base class constructors in the following method of
inheritance?
class A: public B, virtual public C {….};
A) B(); C(); A();
B) C(); B(); A();
C) A(); B(); C();
D) B(); A(); C();
ANSWER B) C(); B(); A();
102. While the friend functions and the member functions of a friend class can have direct access
toboth the private and protected data, the member functions of a derived class can directly access
only the ………… data.
A) protected
B) private
C) public
D) friend
ANSWER A) protected
104. In ……………….. inheritance, the base classes are constructed in the order in which they
appear in the deceleration of the derived class.
A) multipath
B) multiple
C) multilevel
D) hierarchical
ANSWER B) multiple
106. The member functions of a derived class can directly access only the ……………….. data.
A) private and protected
B) private and public
C) protected and public
D) private, protected and public
ANSWER C) protected and public
107.The friend functions and the member functions of a friend class can directly access the
………………. data.
A) private and protected
B) private and public
C) protected and public
D) private, protected and public
ANSWER A) private and protected
108.Object based language differs from object oriented language as it does not support features
_____ .
1. Encapsulation
2. Inheritance
3. Dynamic Binding
4. Abstraction
5. Polymorphism
a. only 3 ,4
b. only 1,3,5
c. 2,4,5
d. Only 2,3
ANSWER: Only 2,3
113. What will happen when introduce the interface of classes in a run-time polymorphic
hierarchy?
a) Separation of interface from implementation
b) Merging of interface from implementation
c) Separation of interface from debugging
d) Merging of interface from debugging
Answer: a
Explanation: Separation of interface from implementation introduce the interface of classes in a
run-time polymorphic hierarchy.
115.Which function is used to position back from the end of file object?
a) seekg
b) seekp
c) both seekg & seekp
d) seekf
nswer: a
Explanation: The member function seekg is used to position back from the end of file object.
116. Which member function is used to determine whether the stream object is currently
associated
with a file?
a) is_open
b) buf
c) string
d) is_out
Answer: a
Explanation: The member function is_open can be used to determine whether the stream object
is currently associated with a file.
117. Which header file is used for reading and writing to a file?
a) #include<iostream>
b) #include<fstream>
c) #include<file>
d) #include<fe>
Answer: b
118.It is not possible to combine two or more file opening mode in open () method.
a. True
b. False
ANSWER: False
128. Where should we place catch block of the derived class in a try-catch block?
a) Before the catch block of Base class
b) After the catch block of Base class
c) Anywhere in the sequence of catch blocks
d) After all the catch blocks
Answer: a
Explanation: C++ asks the programmer to place the catch block of derived class before a catch
block of the base class, otherwise derived catch block will never be executed.
131. In nested try-catch block, if the inner catch block gets executed, then______________
a) Program stops immediately
b) Outer catch block also executes
c) Compiler jumps to the outer catch block and executes remaining statements of the main()
function
d) Compiler executes remaining statements of outer try-catch block and then the main() function
Answer: d
Explanation: The inner catch block will be executed then remaining part of the outer try block
will be executed and then the main bock will be executed.
132. If inner catch block is unable to handle the exception thrown then__________
a) The compiler looks for the outer try-catch block
b) Program stops abnormally
c) The compiler will check for appropriate catch handler of the outer try block
d) The compiler will not check for appropriate catch handler of the outer try block
Answer: c
Explanation: In such cases, the compiler will try to find an appropriate outer catch block to
handle the exception otherwise if nothing is there then occurs the abnormal behaviour of the
program.
135. Pick out the correct objects about the instantiation of output stream.
A. cout
B. cerr
C. clog
D. All of the mentioned
Answer: Option D
Explanation:
cout, cerr and clog are the standard objects for the instantiation of output stream class.
136. What is meant by ofstream in c++?
A. Writes to a file
B. Reads from a file
C. Both a & b
D. None of the mentioned
Answer: Option A
Explanation:
ofstream is a stream class to write on files.