List of C++ Multiple-Choice Questions and Answers
List of C++ Multiple-Choice Questions and Answers
A. Dennis Rechard
B. Dennis M. Ritchie
C. Bjarne Stroustrup
D. Anders Hejlsberg
A. 1979
B. 1972
C. 1983
D. 1986
Answer: C) 1983
Explanation: In 1983, the name of the language was changed from "C with Classes" to C++.
B. C
C. Java
D. VB
Answer: B) C
1
4. C++ language is a ___.
6. C++ is a ___.
A. High-level language
2
7. How many keywords are in C++?
A. 32
B. 48
C. 99
D. 95
Answer: D) 95
Explanation: Keywords are also known as reserved words, there are 95 keywords are available
in C++. Some of the C++ keywords are not available in the C language.
8. Which of the following is not a valid keyword in C++ language?
A. while
B. for
C. switch
D. do-while
Answer: D) do-while
Explanation: Do-while is a control statement, here "do" and "while" are different keywords.
Answer: A) Identifiers are the combination of alphanumeric characters that can be used for
function and variable names.
3
10. Which of the following is used for single-line comment in C++?
A. //
B. \\
C. /* */
D. ##
Answer: A) //
Explanation: We use "//" for single-line comments in C++.
A. //
B. \\
C. /* */
D. ##
Answer: C) /* */
Explanation: We use "/* */" for multi-line comment in C++.
A. True
B. False
Answer: A) True
Explanation: Yes, we can put comments between the statement in C++ language.
C = A /*2+3*/ + B;
4
13. In which year C++14 was introduced?
A. 2014
B. 2015
C. 2017
Answer: A) 2014
Explanation:
• polymorphic lambdas
• digit separators
• generalized lambda capture
• variable templates
A. Assembler
B. Interpreter
C. Compiler
Answer: C) Compiler
Explanation: In C++, a Compiler is used to process C++ source files and generate object files.
5
15. Which of the following whitespace characters can be used in C++?
1. Horizontal tab
2. Vertical tab
3. Form feed
4. New line
Options:
A. 1 and 2
B. 3 and 4
C. 1, 3, 4
D. All 1,2,3,4
Answer: D) All 1,2,3,4
Explanation:
• Horizontal tab
• Vertical tab
• Form feed
• New-line
16. Which of the following is the correct extension of the C++ source code file?
A. .cpp
B. .c++
C. Both
D. None
Answer: c) Both
Explanation: We can use both ".cpp" and ".c++" for a C++ source code file.
6
17. Which of the following command is used for the C++ compiler in Linux OS?
A. GCC
B. c++
C. g++
D. None
Answer: C) g++
Explanation: The g++ command is used to compile C++ source files.
A. True
B. False
Answer: B) False
Explanation: C++ is not a pure object-oriented language because it supports the oops concept as
well as procedural-oriented features.
A. True
B. False
Answer: B) False
Explanation: C++ does not support automatic garbage collection. Here we need to free
dynamically allocated memory using free() or delete. Otherwise, it may cause memory leaks.
A. True
B. False
Answer: A) True
Explanation: Yes, C++ is a case-sensitive language. Here Var1 and var1 will treat differently.
7
21. Which of the following OOPs concepts are supported in C++?
1. Inheritance
2. Encapsulation
3. Abstraction
4. Polymorphism
Opation:
A. 1 and 2
B. 1, 2, and 3
C. 1, 2, and 4
D. All 1,2,3,4
Answer: D) All 1,2,3,4
Explanation:
2. Encapsulation
3. Abstraction
4. Polymorphism
22. OOPs stands for?
8
23. Is it true, C++ is a superset of C language?
A. True
B. False
Answer: A) True
Explanation: Yes, C++ is known as a superset of C. Because C++ supports almost all the
features of C language.
A. True
B. False
Answer: A) True
B. Sequence of bytes
C. Set of errors
26. If the set of bytes flows from main memory to other devices like printers, the monitor is
known as ___.
A. Input Operation
B. Output Operation
C. Both of above
A. <iomanip.h>
B. <iostream.h>
C. <fstream.h>
Answer: B) <iostream.h>
Explanation: The <iostream.h> header file is used to define cin and cout.
A. Library functions
B. structures
C. Pointers
D. objects
Answer: D) objects
Explanation: The cin and cout are the objects of the istream and ostream classes respectively
that are used to perform input/output operations.
B. cout
C. cput
D. cerr
Answer: C) cput
10
30. The stdout stands for ___.
A. State Output
B. Standard Output
C. Stand Output
D. Stream Output
A. True
B. False
Answer: A) True
Explanation: Yes, it is true, the cerr is an object of the ostream class, which is used to output the
errors.
B. >>
C. ->
D. <<<
Answer: A) <<
Explanation: In C++, "<<" is known as the insertion operator which is used with the "cout"
object to print data on the console screen.
11
33. Which of the following is an extraction operator in C++?
A. >>>
B. >>
C. ->
D. <<<
Answer: B) >>
Explanation: In C++, ">>" is known as an extraction operator which is used with the "cin"
object to read user input.
34. The endl is a ___.
A. Macro
B. object
C. Pointers
D. function
Answer: A) Macro
Explanation: The endl is an object of ostream classes, which is used to print newline on the
console screen.
35. Which of the following object is also used to flush the stream?
A. cin
B. cout
C. cerr
D. endl
Answer: D) endl
Explanation: The "endl" object is used to print the newline as well as flush the stream.
12
36. Which of the following namespace contains cin, cout objects?
A. ost
B. std
C. endl
Answer: B) std
Explanation: The "std" namespace contains cin, and cout objects.
1. Basic Datatype
2. Derived Datatype
3. Enumeration data type
Options:
A. 1 and 2
B. 1, 2, and 4
C. 1, 2, and 3
D. All, 1, 2, 3, 4
Answer: D) All, 1, 2, 3, 4
Explanation:
1. Basic Datatype
2. Derived Datatype
13
38. The size of basic datatypes can be changed according to 32 or 64-bit operating systems?
A. True
B. False
Answer: A) True
Explanation: Yes, it is true, the size of basic datatypes can be changed according to 32 or 64-bit
operating systems.
39. If we use value "3.14" then what will be the data type of the given value?
A. float
B. double
C. long double
Answer: B) double
Explanation: If we use any floating-point value with the suffix "F" in C++ that will be double
type.
40. Which of the following is the correct format specifier for long double-type values in
C++?
A. %f
B. %ld
C. %lf
D. %ldf
Answer: C) %lf
Explanation: The "%lf" format specifier is used for long double in C++.
A. 8 bytes
B. 10 bytes
C. 12 bytes
D. 16 bytes
Answer: B) 10 bytes
14
Explanation: The size of a long double in C++ is 10 bytes.
B. False
Answer: A) True
A. int
B. float
C. array
D. char
Answer: C) array
Explanation: The "array" is a derived datatype in C++. It is not a fundamental datatype in C++.
44. Can we create a character variable that will occupy more than 1 byte in memory?
A. True
B. False
Answer: A) True
Explanation: Yes, in C++, using wchar_t we can declare a variable that will occupy more than 1
byte of memory space.
45. For which type, the format specifier "%i" is used?
A. int
B. float
C. array
D. char
Answer: A) int
Explanation: We can use a "%d" or "%i" format specifier for integer variables in C++.
15
46. Which of the following is not a correct qualifier in C++?
A. Size qualifier
B. Type qualifier
C. Sign qualifier
1. Size qualifier
2. Sign qualifier
3. Type qualifier
47. By default, "int" is?
A. Signed integer
B. Unsigned integer
Answer: A) Signed integer
48. The data type "short" and "short int" are similar in C++?
A. True
B. False
Answer: A) True
B. 2
C. 3
D. 4
Answer: B) 2
Explanation: In C++, the short or short int takes 2 bytes (16 bits) in memory.
16
50. The operator '+' is?
A. Unary Operator
B. Binary Operator
A. Division Operator
B. Modulus Operator
C. Percentage Operator
B. !=
C. ::
D. ?:
Answer: D) ?:
Explanation: In C++, the operator '?:' is a ternary operator, it operates on 3 operands, it is also
known as a conditional operator.
17
53. Which of the following operator is known as Scope Resolution Operator?
A. ::
B. ?:
C. ->
D. .
Answer: A) ::
Explanation: In C++, the operator '::' is known as the Scope Resolution operator.
A. !=
B. ?:
C. ->
D. sizeof
Answer: C) ->
Explanation: In C++, the operator '->' is known as the Referential operator.
A. Unary Operator
B. Binary Operator
C. Ternary Operator
A. Left to Right
B. Right to Left
Answer: B) Right to Left
18
57. The associativity of the "[]" operator is?
A. Left to Right
B. Right to Left
B. Right to Left
Explanation: In C++, the associativity of the conditional operator "?:" is Right to Left.
59. Which of the following operator is used to return the address of a variable?
A. *
B. ->
C. &
Answer: C) &
Explanation: In C++, the "&" operator is used to return the address of a variable.
60. Which of the following is known as the "value of" operator?
A. *
B. ->
C. &
D. None of the above
Answer: A) *
Explanation: In C++, the "*" operator is known as the "value of" operator.
19
61. Which of the following is known as the "NOT" operator?
A. ~
B. !
C. NOT
Answer: B) !
Explanation: In C++, the "!" operator is known as the "NOT" operator.
A. %
B. /
C. !
D. *
Answer: C) !
Explanation: In C++, the "!" operator is not an arithmetic operator, it is a logical operator.
63. Which of the following statement is correct about the global variable?
Answer: B) A variable defined outside the function or block is known as a global variable.
B. False
Answer: B) False
Explanation: The system automatically initializes a global variable whereas we need to initialize
local variables explicitly.
20
65. The default value of a variable that is declared using register storage class?
A. 0
B. Garbage
Answer: B) Garbage
Explanation: The default value of the variable, which is declared using the register storage class
is garbage.
A. auto
B. extern
C. register
D. static
Answer: A) auto
Explanation: The "auto" is the default storage class in C++.
A. True
B. False
Answer: A) True
68. Which of the following escape sequence is used to print double quotes on the console
screen?
A. %”
B. /”
C. *”
Answer: B) /”
Explanation: The escape sequence /" prints double quotes on the console screen.
21
69. Which of the following escape sequence is used to print the percentage symbol on the
console screen?
A. %%
B. /%
C. *%
D. None of the above
Answer: A) %%
Explanation: The escape sequence %% is used to print the percentage symbol on the console
screen.
Answer: B) Arguments with a default value that is not mandatory to be passed into the function
Explanation: In C++, we can create functions with default arguments. The default arguments are
used with a default value that is not mandatory to be passed into the function.
71. Which of the following condition is correct for the default arguments?
Answer: A) Default arguments must be the last arguments in the function declaration.
Explanation: In C++, we can create functions with default arguments. The default arguments
must be the last argument in the function declaration.
22
72. Which of the following function can be called without any arguments?
74. Which of the following function will be called with the independent syntax
"sample(10,20,30);"?
A. void sample(int x, int y)
Explanation: In the above options, option D is correct. Option C is incorrect because the return
type is "float" and the syntax given is independent which means it doesn't return any value.
23
75. Which of the following is an incorrect call to the function void sample(int a, int b=0, int
c=0)?
A. sample(10,20,30);
B. sample();
C. sample(50);
D. sample(30,40);
Answer: B) sample();
A. Default arguments are allowed in the argument list of the function declaration.
B. Default arguments are allowed in the return type of the function declaration.
Answer: A) Default arguments are allowed in the argument list of the function declaration.
Explanation: Default arguments are allowed in the argument list of the function declaration.
77. Which of the following statement is not correct about Default arguments?
A. Default arguments are allowed with pointer and reference to function declaration.
Explanation: Default arguments are not allowed with pointer and reference to function
declaration.
24
78. The default argument gets bound during declaration but is executed during the
function call?
A. True
B. False
Answer: A) True
Explanation: Yes, the default argument gets bound during declaration but is executed during the
function call.
79. Can we implement a constructor with a default argument?
A. True
B. False
Answer: A) True
Explanation: Yes, we can implement a constructor with a default argument.
A. 6
B. 5
C. 4
D. 3
Answer: B) 5
Explanation: There are following sequence of statements is available in C++:
1. Pre-processor directives
2. Comments
3. Declarations
4. Function Declarations
5. Executable statements
25
81. Which of the following is/are a decision making statement?
1. IF statements
2. Switch statement
3. Conditional operators
Options:
A. 1 and 2
B. 1 and 3
C. 4
D. 1, 2, and 3
Answer: D) 1, 2, and 3
• IF statements
• Switch Statements
• Conditional operators.
82. Which of the following statement can replace the if-else statement?
A. while loop
B. do-while loop
C. for loop
D. conditional operator
26
83. Which of the following is the best option to make decisions for multiple choices?
A. if
B. if-else
C. if-else-if
Answer: C) if-else-if
Explanation: In C++, "if-else-if" is the best option for multiple choices.
84. Can we use the string in the Switch statement for case selection?
A. True
B. False
Answer: B) False
Explanation: In C++, we cannot use the string in Switch stamen for case selection.
B. Do While loop
Explanation: While loop is an entry control loop, in a "while" loop we need to check the
condition before executing the loop body.
C. For loop
Explanation: The do-while loop is an entry control loop, in the "while" loop we need to check
the condition before executing the loop body.
27
87. Which of the following loop is normally used for a menu-driven program?
A. Do While loop
B. For loop
C. While loop
88. Which of the following loop, in which we have to execute the body of the loop before
checking the condition?
A. Do While loop
B. For loop
C. While loop
D. None of the above
Explanation: In the Do-while loop, we have to execute the body of the loop before checking the
condition.
89. Which of the following types of variables can be used in the Switch statement for case
selection?
B. int, char
C. int, double
D. Any fundamental type
Explanation: We can use only int, char type variables in the switch statement for case selection.
28
90. In switch statements, Expression in parenthesis "( )" after the switch statement is
mandatory?
A. True
B. False
Answer: A) True
Explanation: Yes, the Expression in parenthesis "()" after the switch statement is mandatory.
91. Which of the following statement is correct about the "break" statement?
A. Do While loop
B. For loop
C. While loop
A. continue
B. break
C. while
Answer: B) break
29
94. Which of the following statement is also known as a "switch" statement?
A. selective statement
B. choose statement
C. bitwise statement
D. certain statement
A. goto statement
B. bitwise statement
C. skipping statement
D. certain statement
96. Which of the following is the correct syntax of the "for" loop?
30
97. Which of the following is the correct syntax of the "do-while" loop?
98. Which of the symbol is used with the label in the "goto" statement?
A. @
B. :
C. #
D. !
Answer: B) :
Explanation: The colon ":" symbol is used with the label in the "goto" statement.
99. Which of the following loop is the best option when the number of iterations is known?
A. While loop
B. For loop
C. Do while loop
Explanation: The "for" loop is the best option when the number of iterations is known.
31
100. Execution of C++ program starts from?
A. void function
B. class
C. main function
D. user-defined function
101. Which of the following given option is used to complete the function declaration?
A. Semicolon
B. Colon
C. Comma
Answer: C) Comma
Explanation: The semicolon is used to complete the function declaration.
A. 128
B. 256
C. 512
Explanation: It varies from compiler to compiler and also different C99 and C++ standards.
32
103. Which of the following are the mandatory part of the function prototype?
33
104. What will be the output of the following program?
#include <iostream>
using namespace std
void sayHello();
{
cout << "Hello World";
}
int main()
{
sayHello();
return 0;
}
Options:
A. Hello World
B. Hello
C. Error
Answer: B) CSS
Explanation: The above program will generate a syntax error because we use a semicolon in the
definition of the sayHello() function. The correct program is given below:
#include <iostream>
using namespace std;
void sayHello()
{
cout << "Hello World";
}
int main()
{
sayHello();
return 0;
}
34
105. Can we use the return type void in the main() function in a C++ program?
A. Yes
B. No
Answer: B) NO
Explanation: No, we cannot use the return type void in the main () function, we have to use the
return type "int" with the main() function.
106. Which of the following is a more effective way to call a function with arguments?
A. Call by value
B. Call by reference
C. Call by address
107. How many minimum numbers of functions are required to execute a C++ program?
A. 1
B. 2
C. 3
D. 4
Answer: A) 1
Explanation: To execute a C++ program, we required only 1 function which is the main()
function. Because the main() function is the entry point for the program.
35
108. What is the lifetime of a static variable declared in a user-defined function?
C. Whole program
Explanation: A function that is substituted at the place of call is called an inline function.
110. A function that is defined inside a class without any complex statement will be inline.
A. True
B. False
Answer: A) True
Explanation:
Yes, A function that is defined inside a class without any complex statement will be inline.
A. Compile Time
B. Runtime
Explanation: An inline function is substituted at the place of the function call during compile
time.
36
112. A recursive function can be inline?
A. Yes
B. No
Answer: B) NO
B. No
Answer: B) NO
A. Yes
B. No
Answer: A) Yes
Explanation: Yes, an inline function is faster than a normal function because it does not require
a context switch from function call to function definition.
115. Default values for a function are defined.
A. In function declaration
B. In function definition
C. During function call
D. None of the above
Explanation: We can define default values for a function in the function declaration.
37
116. Can we define the inline function outside the class in C++ program?
A. Yes
B. No
Answer: A) Yes
Explanation: Yes, we can define an inline function inside or outside the class.
B. No
Answer: B) NO
Explanation: No, we cannot access the elements of an array outside the bound in C++. It can
generate logical and runtime errors.
B. 2
C. 0
D. -1
Answer: C) 0
38
120. If we create an array "Arr", which is the correct way to access the first element of the
array?
A. Arr[0]
B. 0[Arr]
C. *(Arr+0)
D. All the above
Explanation: All the given options are the correct way to access the first element of the array.
121. Can we create an array of objects in C++?
A. Yes
B. No
Answer: A) Yes
Explanation: Yes, we can create an array of objects in C++.
A. Yes
B. No
Answer: A) Yes
Explanation: Yes, we can create a 4-dimensional array using the below statement.
int arr[2][2][2][2];
A. Contiguous manner
B. Fragmented manner
C. Linked List
D. None
39
124. How many dimensions are an array in C++?
A. 1D array
B. 2D Array
C. 3D array
D. No Limit
Answer: D) No Limit
Explanation: There is no limit of dimensions for arrays in C++.
125. When we pass an array to the function, then the function call will be?
A. Call by value
B. Call by reference
C. Both A and B
D. None of these
126. Which of the following statement is correct about the is_array() function in C++??
A. The is_array() function is used to check whether a variable is an array or not.
Explanation: The is_array() function is used to check whether a variable is an array or not.
40
127. Which of the following statement is correct about the is_same() function in C++?
C. The is_same() function is used to check if two variables have the same characteristics.
D. None of these
Answer: C) The is_same() function is used to check if two variables have the same
characteristics.
Explanation: The is_same() function is used to check if two variables have the same
characteristics.
128. Which of the following function is used to get the dimensions of the given array?
A. getdimension
B. getarraydimension
C. rank
D. arrayrank
Answer: C) rank
Explanation: The rank function is used to get the dimensions of the given array.
129. Which of the following function is used to remove all dimensions from an array?
A. remove_dimension
B. remove_all_dimensions
C. remove_extent
D. remove_all_extents
Answer: D) remove_all_extents
Explanation: The remove_all_extents is used to remove all dimensions from an array.
41
130. Which of the following contains an array type manipulation function?
A. std namespace
B. <iostream>
C. <array>
131. Is it true, when array initialization is part of the definition then the size of the array is
not required?
A. True
B. False
Answer: A) True
Explanation: Yes, the size of the array is not required when we initialize an array as part of the
definition.
B. &
C. *
D. None of the above
Answer: C) *
B. &
C. *
C. int *ptr;
A. True
B. False
Answer: B) False
Explanation: No, we cannot point to a datatype using a pointer.
A. int *ptr;
B. int* ptr;
C. int &ptr;
D. int *ptr=0;
B. NULL
C. 0
Explanation: A pointer can be initialized with the address of a variable of the same type, NULL,
and zero.
43
138. Which of the following is the correct way to get value from pointer "ptr"?
A. ptr
B. &ptr
C. *ptr
Answer: C) *ptr
Explanation: The "*ptr" is the correct way to get the value from the pointer ptr.
A. 4 bytes
B. 8 bytes
C. 16 bytes
B. No
Answer: A) Yes
Explanation: Yes, we can create a pointer to point a file in c++ using the "FILE*" type.
44
142. What will be the output of the following program?
#include <iostream>
using namespace std;
int main()
p1 = p2;
return 0;
}
Options:
A. 50
B. 20
C. Address
D. Error
Answer: B) Address
Explanation: Here, initially, pointer p1 points to variable x, and pointer p2 points to y variable.
Then pointer p2 is assigned to pointer p1. So when we print *p2 then it will print the value of
variable "y" which is 20.
A. Yes
B. No
Answer: B) No
Explanation: An uninitialized pointer is known as a wild pointer while a dangling pointer points
to a location that has been deleted.
45
144. Which of the following can point to any type of variable?
A. Far pointer
B. Null pointer
C. Void pointer
D. Dangling pointer
A. 16-bit
B. 32-bit
C. 64-bit
D. None of the above
Answer: B) 32-bit
146. Can we access memory outside the current segment using a far pointer?
A. Yes
B. No
Answer: A) Yes
Explanation: Yes, we can access memory outside the current segment using a far pointer.
147. Which of the following is the incorrect type of pointer in C++?
A. Near
B. Far
C. Huge
D. Small
Answer: D) Small
46
148. In Smart pointer, we did not require to take care to deallocate memory space?
A. Yes
B. No
Answer: A) Yes
Explanation: Yes, In smart pointers we did not require to take care to deallocate memory space,
allocated memory will be free automatically.
149. Which of the following is not the correct type of smart pointer?
A. unique_ptr
B. shared_ptr
C. week_ptr
D. far_ptr
Answer: D) far_ptr
Explanation: The "far_ptr" is not the correct type of smart pointer in C++.
A. Yes
B. No
Answer: B) NO
Explanation: The "unique_ptr" does not maintain a reference counter while "shared_ptr"
maintains a reference counter.
151. Which of the following function is used to maintain a reference counter with a smart
pointer?
A. use_count()
B. count()
C. ptr_count()
D. shared_count()
Answer: A) use_count()
47
152. Which type of memory is allocated using dynamic memory allocation?
A. Stack
B. Heap
C. Static
D. Program code
Answer: B) Heap
Explanation: When we use dynamic memory allocation, memory is allocated in the heap
segment.
153. Which of the following is/are used for dynamic memory allocation?
1. malloc
2. calloc
3. new
4. free
Options:
A. 1 and 2
B. 1, 2, and 4
C. 2 and 3
B. No
Answer: A) Yes
Explanation: Yes, we can allocate memory for an object using "new" and malloc() in C++.
48
155. Is it not required to deallocate the dynamically allocated memory manually in the
program?
A. Yes
B. No
Answer: B) No
Explanation: We need to manually deallocate the dynamically allocated memory using free()
and delete operator in our program.
156. Which of the following operator is used to release dynamically allocated memory
space?
A. new
B. remove
C. release
D. delete
Answer: D) delete
Explanation: The "delete" operator is used to release dynamically allocated memory space.
A. Yes
B. No
Answer: B) No
Explanation: No, "new" is an operator in C++, which is used to allocate memory space
dynamically.
158. When we allocate memory space for an object using "new", will it call a constructor?
A. Yes
B. No
Answer: A) Yes
Explanation: Yes, when we allocate memory space for an object using the "new" operator, it
will call the constructor. But when we allocate memory space for an object using the "malloc ()"
function, it will not call the constructor.
49
159. On failure, the "new" operator returns?
A. NULL
B. -1
C. bad_alloc exception
D. None of these
A. Yes
B. No
Answer: A) Yes
Explanation: Yes, "delete" is an operator in C++, which is used to deallocate memory space
dynamically.
161. During the deallocation of dynamically allocated memory for an object using the
"free()" function destructor gets called?
A. Yes
B. No
Answer: B) No
Explanation: No, the "free()" function does not call the destructor while the "delete" operator
call destructor during the deallocation of dynamically allocated memory for an object.
162 . Which of the following is a valid way to allocate dynamic memory for an integer
variable?
50
163. Which of the following is correct?
Answer: A) "ptr = calloc(a, b)" is equivalent to ptr = malloc(a * b); memset(ptr, 0, a * b);
Explanation: Option A is correct.
#include <stdio.h>
int main()
{
ptr = NULL;
free(ptr);
Options:
A. Memory leak
B. Dangling pointer
C. Compiler error
51
165. Which programming language required heap memory allocation in the run time
environment?
Explanation: A language that allows dynamic data structures required heap memory allocation
in the run time environment.
C. Class is a blueprint for a data type that encapsulates data member and member functions.
Answer: C) Class is a blueprint for a data type that encapsulates data member and member
functions.
Explanation: Class is a blueprint for a data type that encapsulates data member and member
functions.
167. Which of the following symbol is used at the end of the class definition?
A. Colon.
B. Semicolon.
C. Scope Resolution operator.
Explanation: The semicolon ( ; ) symbol is used at the end of the class definition.
52
168. Can we define member functions outside the class?
A. Yes
B. No
Answer: A) Yes
Explanation: Yes, we can define member functions inside or outside the class.
169. Which of the following symbol is used to define member functions outside the class?
A. Colon.
B. Semicolon.
Explanation: The scope resolution operator ( :: ) symbol is used to define member functions
outside the class.
A. Public
B. Private
C. Protected
Answer: B) Private
Explanation: By default, members of a class are private in C++.
171. Can we define a constructor inside the structure?
A. Yes
B. No
Answer: A) Yes
Explanation: Yes, just like class, we can define a constructor inside the structure in C++.
53
172. By default, members of a structure are:
A. Public
B. Private
C. Protected
Answer: A) Public
Explanation: By default, members of a structure are public in C++.
A. Yes
B. No
Answer: A) Yes
Explanation: Yes, just like class, we can define a destructor inside the structure in C++.
B. 0 Byte
C. 2 Byte
D. 4 Byte
Answer: A) 1 Byte
Explanation: The size of an empty class is 1 byte, every object occupies at least one byte to
differentiate memory address space for objects.
175. Can we create multiple objects of a class in C++?
A. Yes
B. No
Answer: A) Yes
54
176. Which of the following operator is used to access the members using the object of a
class?
A. .
B. ->
C. :
D. None of the above
Answer: A) .
Explanation: The membership operator (.) is used to access the members using the object of a
class in C++.
177. Which of the following operator is used to access the members using the pointer to the
object of a class?
A. .
B. ->
C. :
Answer: B) ->
Explanation: The referential operator -> is used to access the members using the pointer to the
object of a class in C++.
B. No
Answer: A) Yes
Explanation: Yes, objects of a class do not share non-static members. Every object has its own
copy.
55
179. Can we create a "const" object in C++?
A. Yes
B. No
Answer: A) Yes
Explanation: Yes, we can create a "const" object in C++, using a "const" object. Any attempt to
change the data member of const objects results in a compile-time error.
A. Yes
B. No
Answer: A) Yes
Explanation: Yes, we can create "const" member functions in the class. In the "const" member
function, we cannot change the value of data members.
A. Yes
B. No
Answer: B) No
Explanation: No, we cannot pass a class into a function as an argument, we can pass an object
of a class as an argument to the function in C++.
56
182. How many types of specifiers can be used in class in C++?
A. 1
B. 2
C. 3
D. 4
Answer: C) 3
Explanation: There are 3 types of specifiers used in class are given below:
1. Public
2. Private
3. Protected
4. 183. Which of the following is/are the correct type of class?
A. Abstract class
B. Concrete class
C. Both A and B
A. Yes
B. No
Answer: A) Yes
Explanation: Yes, we can create objects of class at the end of the class definition before the
semicolon. For example.
class Sample {
int a, b;
obj1, obj2;
57
185. Which of the following statement is correct about constructors in C++?
C. Constructor is used to call the private function from outside the class.
Answer: B) Constructor is used to initializing data members when an object gets created.
Explanation: Constructor is a special type of member function that automatically calls when an
object gets created. It is used to initialize the data members of the class.
186. How many parameters can be accepted by a default constructor?
A. 1
B. 2
C. 0
D. Infinite
Answer: C) 0
B. int
C. float
D. None of the above
Answer: D) None of the above
58
188. Which of the following is an incorrect type of constructor in C++?
A. Copy constructor
B. Move constructor
C. Default constructor
D. Parameterized constructor
189. If we did not create any constructor in the class, then which of the following
constructor is automatically added to the class?
A. Copy constructor
B. Default constructor
C. Parameterized constructor
D. None of the above
Explanation: If we did not create any constructor in the class, then the default constructor is
automatically added to the class.
A. Yes
B. No
Answer: B) No
Explanation: Yes, we can create multiple constructors in a class by overloading the constructor.
B. No
Answer: A) Yes
Explanation: Yes, the constructor can be inline, as we know, inline is a request, not a command.
59
192. A default constructor is also known as a?
A. Parameterized constructor
B. Copy constructor
C. No argument constructor
A. Linker error
B. Compilation error
C. Logical error
B. False
Answer: B) False
Explanation: No, when we create an object of class using the malloc() function then the
constructor will not call, the constructor gets called when we use the "new" operator for object
creation.
60
195. Constructor and Destructor have the same name but destructor is preceded by?
A. ~
B. !
C. $
D. #
Answer: A) ~
Explanation:
Constructor and Destructor have the same name but destructor is preceded by a tilde (~) symbol.
A. Yes
B. No
Answer: B) No
A. Yes
B. No
Answer: B) No
Explanation: No, we cannot create a virtual constructor in a class. Other than inline, no other
keyword is allowed in the declaration of the constructor.
198. Can we create a virtual destructor in a class?
A. Yes
B. No
Answer: A) Yes
Explanation:
61
199. Which of the following constructor is used to create an object by initializing data
members using an existing object?
A. Default constructor
B. Dynamic constructor
C. Copy constructor
D. None of the above
200. Can we implement copy constructor without passing reference of an object into it?
A. Yes
B. No
Answer: B) No
201. Which of the following is used to initialize the const members of the class using a
constructor?
A. Const constructor
B. Default constructor
C. Member initializer list
D. Copy constructor
Answer: C) Member initializer list
Explanation: In C++, a member initializer list is used to initialize the const members of the
class.
62
202. Which of the following is responsible to create a default constructor in the class when
the programmer does not create a constructor inside the class?
A. Compiler
B. Linker
C. Loader
D. Pre-processor
Answer: C) Loader
Explanation: In C++, the Compiler is responsible to create a default constructor in the class
when the programmer does not create a constructor inside the class.
204. When we deallocate space for an object of class using the free() function then a
destructor gets called?
A. True
B. False
Answer: B) False
Explanation: No, when we deallocate space for an object of class using the free () function then
a destructor will not call, the destructor gets called when we use the "delete" operator for object
destruction.
63