Multiple choice questions in C++

https://www.youtube.com/watch?v=TFwStqMO8qM
Multiple Choice Questions in C++



Multiple choice questions in C++ (With answers)

1. An entity representing some characteristics and behaviour is-
a) object
b) class
c) struct
d) none of the above

2. Which of the following is not the feature of OOPs?
a) Data Encapsulation
b) Inheritance
c) Polymorphism
d) None of the above
3. The wrapping up of data and functions into a single unit is
a) Data Abstraction
b) Data Encapsulation
c) Both (a) & (b)
d) None of the above

4. Which of the following feature supports reusability and extensibility of classes?
a) Inheritance
b) Overloading
c) Polymorphism
d) None of the above

5. Inheritance is ………..in nature.
a) Intransitive
b) Transitive
c) Both (a) & (b)
d) None of the above

6. ………… is the ability for a message or data to be processed in more than one form
a) Class
b) Abstraction
c) Polymorphism
d) None of the above

7. The smallest individual unit in a program is ………
a) Keyword
b) Identifier
c) Token
d) None of the above

8. Which of the following features of procedure oriented programming is false
a) Large programs are divided into small or units called functions.
b) Employs bottom-up approach in program design.
c) Most of the functions share global data.
d) None of the above.

9. Which of the following features of object oriented programming is false?
a) Data is hidden and is not available to external functions.
b) New data & functions can be added easily.
c) Objects may communicate with each other through functions.
d) Emphasis is on the procedure rather than data.

10. The following is the C++ style comment
a) //
b) /*..*/
c) —
d) None of the above

11. Which of the following statements is false?
a) Every C++ program must have a main().
b) In C++, white spaces and carriage returns are ignored by the compiler.
c) C++ statements terminate with semicolon.
d) Main() terminates with semicolon.

12. An identifier in C++
a) Must begin with a letter only
b) Is not differentiated by cases
c) Contains all characters as significant
d) None of the above

13. 010 is an example of
a) decimal constant
b) octal constant
c) hexadecimal constant
d) None of the above

14. A sequence of characters surrounded by double quotes is
a) Character literal
b) String literal
c) Both (a) & (b)
d) None of the above

15. The following data type specifies an empty set of values
a) Void
b) Int
c) Char
d) None of the above

16. ………. Provides a value for a variable
a) declaration statement
b) assignment statement
c) definition statement
d) None of the above

17. A collection of variables referred under one name
a) Structure
b) Class
c) Union
d) None of the above

18. A memory location shared by two or more different variables
a) Structure
b) Class
c) Union
d) None of the above

19. The constants defined using enum keyword are
a) Symbols
b) Enumerators
c) Keywords
d) None of the above

20. The operator ?: is
a) Logical operator
b) Relational operator
c) Conditional operator
d) Arithmetic operator

21. A loop containing other loop is
a) Nested
b) Inner
c) Outer
d) None of the above

22. The following statement forces the next iteration of the loop to take place
a) break
b) continue
c) goto
d) None of the above

23. gets() function is available in
a) stdio.h
b) string.h
c) ctype.h
d) stdlib.h

24. In C++, the statements are enclosed within
a) parenthesis
b) square brackets
c) curly brackets
d) None of the above

25. The following tells the compiler where the program begins
a) Function prototype
b) Forward declaration of class
c) main()
d) None of the above

26. << operator is
a) stream insertion operator
b) stream extraction operator
c) left shift operator
d) None of the above

27. “H” is an example of
a) character literal
b) string literal
c) variable
d) None of the above

28. Which of the following statements regarding comments is false?
a) /*..*/
b) Comment beginning with // extends to the end of the line
c) Comments may be nested
d) Comments are used to describe a program

29. C++ is
a) Procedural programming language
b) Structural programming language
c) Object oriented programming language
d) None of the above

30. y=x=2; in C++ will result in
a) compilation error
b) runtime error
c) assignment of value to x then to y
d) None of the above

31. In C++, ………. is the statement terminator
a) semicolon
b) colon
c) new line
d) None of the above

32. Modules operator (%) has higher precedence than
a) Divide (/) operator
b) Multiply (*) operator
c) Negation (unary minus)
d) Bitwise left shift operator

33. The result of the following statement is
int y = 7;
int ans = ++y;
cout<<”ans=”<<ans;
cout<<”y”<<y;

a) ans=7, y=7
b) ans=8,y=7
c) ans=8,y=8;
d) none of the above

34. Consider the following if construct
If(x=0)
cout<<”Inside loop!”;
cout<<”Outside loop”;
The result of the above code segment is.

a) inside loop
b) outside loop
c) both (a) & (b)
d) none of the above

35. The result of 2 & 3 is
a) 2
b) 3
c) 5
d) none of the above

36. Which of the following statements regarding enumerators is false?
a) Enumeration is an alternative method for naming integer constants/
b) An enumerator value can’t be changed in a program
c) An integer value may be assigned to an enumerated variable
d) An enum defined within a structure is local to the structure

37. Which of the following statements is false?
a) typedef defines new data types
b) Using typedef does not replace the standard C++ data type name with the new name
c) The new name defined by typedef, can be used as a type for another typedef
d) None of the above

38. Data members and member functions are enclosed within
a) class
b) structure
c) union
d) None of the above

39. Inline functions are
a) Declared in the class defined outside the class
b) Defined outside the class using keyword intime
c) Defined inside the class using keyword inline
d) None of the above

40. The default class access scope is
a) Private
b) Public
c) Protected
d) None of the above

41. The default scope for a structure is
a) Private
b) Public
c) Protected
d) None of the above

42. The private data members of a class are accessible
a) Directly to objects of that class
b) Only to the member functions
c) To any function defined outside a class
d) None of the above

43. The objects can directly access
a) Public members
b) Private members
c) Both (a) & (b)
d) None of the above

44. The following is a valid statement in C++
a) int x=(int)2.50;
b) int x=int(2.50);
c) Both (a) & (b)
d) None of the above

45. Which of the following operator can be overloaded
a) Member access operator ( . & .*)
b) Conditional operator (?:)
c) Scope resolution operator (::)
d) None of the above

46. Using same function name to perform different tasks is
a) Function polymorphism
b) Runtime polymorphism
c) Function prototype
d) None of the above

47. Default argument is
a) Specified in function definition
b) Specified in function declaration
c) Specified from left to right
d) None of the above

48. What is wrong with the following statement?
float s_interest (float principal, int rate=0.25, int time);

a) variables must not be specified in function prototype
b) arguments may only be defaulted from right to left
c) the default value must be specified when making a function call
d) none of the above

49. Which of the following statements regarding function overloading is not true.
a) If is used to handle different data types at one place
b) When making a function call, if no exact match is found, promotion is the only criteria to find a match.
c) The default arguments can not be used instead of overloading
d) Unrelated functions should not be overloaded

50. The private members of a class implement the OOP concept of
a) Data abstraction
b) Data hiding
c) Message passing
d) None of the above

51. When a member function of a class call another member function, it is
a) Nesting of classes
b) Nesting of functions
c) Nesting of objects
d) None of the above

52. A function defined inside a class is called
a) A class function
b) A friend function
c) A member function
d) None of the above

53. Information is made shareable through
a) inheritance
b) data encapsulation
c) data abstraction
d) none of the above

54. Functions can returns
a) arrays
b) reference
c) object
d) all of the above

55. The memory for date members is allocated
a) When a class is defined
b) When an object is initialized
c) When an object is created
d) None of the above

56. The memory for member functions is allocated
a) When a class is defined
b) When a object is created
c) When an object is initialized
d) None of the above

57. The dot operator relates
a) A class member and a class object
b) A class object and a class
c) A class and a member of that class
d) A class object and member of that class

58. A class having another class definition is
a) Nested class
b) Subordinate class
c) Enclosing class
d) None of the above

59. A class whose member functions are friends of other class is
a) Friend class
b) Abstract class
c) Virtual class
d) None of the above

60. The data members of a class are initialized
a) in class definition
b) by a non-member function
c) through constructor function when a class object is created
d) none of the above

61. A constructor function is
a) A friend function to a class
b) A member function with the same name as its class
c) A non-member function
d) None of the above

62. An enumerated type is composed of
a) Integer values with user defined name
b) Variables of different data types
c) Constant numeric values
d) None of the above

63. In C++, the arguments by default are passed by
a) call be reference
b) call be value
c) both (a) & (b)
d) none of the above

64. ? is an example of
a) unary operator
b) binary operator
c) ternary operator
d) none of the above

65. new operator is used
a) to define a new variable
b) to create a new data type
c) to allocate memory dynamically
d) none of the above

66. A constructor function is generally defined
a) In the public section of a class
b) In the private section of a class
c) In the protected section of a class
d) None of the above

67. A class having no public constructors is
a) A private class
b) A public class
c) An abstract class
d) None of the above

68. If a constructor function is defined in private section of a class, then
a) The object cannot be created
b) Only member functions and friends may declare objects of the class
c) Both (a) & (b)
d) None of the above

69. A constructor with no argument is
a) Default constructor
b) Parameterized constructor
c) Copy constructor
d) None of the above

70. If default arguments are provided to a constructor function, then it becomes
a) Default constructor
b) Copy instructor
c) Parameterized constructor
d) None of the above

71. The class of which the objects are not instantiated is
a) Abstract class
b) Virtual class
c) Static class
d) None of the above

72. && denotes
a) logical OR
b) logical AND
c) Bitwise AND
d) None of the above

73. The parameterized constructor
a) Needs initial values as arguments during creation of an object
b) Can be invoked explicitly only
c) Can be invoked implicitly only
d) None of the above

74. Explicit call to a constructor means
a) Providing the constructor name explicitly to invoke it
b) Not providing the construction name at all
c) Is the shorthand method
d) None of the above

75. Classes in C++ are
a) Fundamental data type
b) Primitive data type
c) Desired data type
d) None of the above

76. A copy constructor is called
a) When an object is defined and initialized with another object
b) When an object is passed by value
c) When a function returns an object
d) All of the above

77. Which of the following regarding constructor function is false?
a) Constructor functions don’t have return type, not even void
b) Constructors can’t be inherited
c) We can refer to their addresses
d) Constructors cannot be virtual

78. If new operator is used, then the constructor function is
a) Parameterized constructor
b) Copy constructor
c) Dynamic constructor
d) Default constructor

79. Which of the following statements regarding constructor is false?
a) A constructor may be defined static
b) Constructor can have default arguments
c) Member functions may be invoked from within a constructor
d) None of the above

80. The antonym of constructor is
a) Creator
b) Destructor
c) Destroyer
d) None of the above

81. Variable …………. of void type
a) May be declared
b) Cannot be declared
c) Can be initialized
d) None of the above

82. A destruction function
a) Takes no argument and has no return type not even void
b) Has name similar to that of class, preceded by tilde(~) symbol
c) Is used to destruct an object, constructed through constructor function
d) All of the above

83. Which of the following statements regarding destructor function is false?
a) Destructors do not accept any arguments, nor do they return any values
b) Destructors can be inherited
c) Member functions may be called from within a destructor
d) Destructor functions are called automatically when an object is destroyed

84. Function overloading
a) Involves several function definitions under one name, but different argument types
b) Implements polymorphism
c) Reduces the number of comparison in a program, hence increases the execution speed of a program
d) All of the above

85. The signature of function is
a) The number & type of arguments
b) The return type of a function
c) The class definition
d) None of the above

86. Overloading of constructor function
a) is similar to function overloading
b) different from an overloaded function as it can’t return a value
c) not permitted in C++
d) none of the above

87. The binding of a function call at runtime is
a) Static binding
b) Early binding
c) Late binding
d) Runtime binding

88. The process of giving special meaning to an operator is
a) Operator overloading
b) Operator mechanism
c) Operator definition
d) None of the above

89. The function used to define the task assigned to an operator is
a) Virtual function
b) Operator function
c) Static function
d) None of the above

90. The following operators can not be overloaded
a) Unary operator
b) Binary operator
c) Ternary operator
d) None of the above

91. Which of the following statements regarding operator overloading is not true?
a) New operators cannot be created while overloading
b) The semantics of an operator cannot be changed while overloading
c) Subscript operator([]) can be overloaded
d) None of the above

92. Which of the following statements can be overloaded?
a) Size of operator
b) Scope resolution operator (::)
c) Class member access operator (->)
d) Pointer to member operator

93. Operator functions
a) Can return a value
b) Cannot return a value
c) May return values of limited data types
d) None of the above

94. While overloading, a unary operator
a) Takes no arguments
b) Takes one argument
c) Takes two arguments
d) None of the above
95. While overloading, a binary operator
a) takes no argument
b) takes one argument
c) takes two arguments
d) none of the above

96. Which of the following operators cannot be overloaded?
a) increment and decrement operator
b) function call operator, ()
c) subscript operator, []
d) none of the above

97. When an arithmetic assignment operator is overloaded, the result
a) goes in the object to the left of the operator
b) goes in the object to the right of the operator
c) goes in the object of which the operator is a member
d) none of the above

98. The function that overloads as operator, precedes with the keyword
a) function
b) operator
c) virtual
d) static

99. The symbol **
a) can be overloaded
b) cannot be overloaded as it is not a C++ operator
c) cannot be overloaded, as on overloading its meaning shall be changed
d) none of the above

100. The stream insertion and extraction operators should be overloaded as
a) friend functions
b) member function
c) non member functions
d) none of the above

101. The following operators cannot be overloaded
a) scope resolution operator
b) size of operator
c) conditional operator
d) all of the above

102. The operator definition precedes with the keyword class
a) class
b) operator
c) overload
d) none of the above

103. The operator function
a) is declared in the public section of the class
b) may be a member function or a friend function
c) both (a) & (b)
d) none of the above

104. The operator functions may be invoked
a) implicitly
b) explicitly
c) both (a) & (b)
d) none of the above

105. The following operator can’t be overloaded
a) unary
b) binary
c) ternary
d) none of the above

106. Which of the following statements regarding operator overloading function is false?
a) While overloading, the semantics of an operator cannot be changed.
b) The operator precedence cannot be changed while overloading.
c) The overloaded operator must have at least one operand that is of user-defined type.
d) You can create new operator symbol.

107. The following operators cannot be overloaded.
a) Logical AND (&&)
b) Subscript operator ([])
c) Equality operator (==)
d) none of the above

108. A unary operator when overloaded takes
a) no operand
b) one operand
c) two operands
d) none of the above]

109. The no of arguments required when overloading through friend functions is
a) Zero
b) One
c) Two
d) None of the above

110. Which of the following statements regarding operator overloading is false?
a) friend function cannot be used to overload certain operators.
b) Unary operators overloaded by means of friend functions takes no argument
c) Binary operators must explicitly return a value
d) The syntax rules of the operators cannot be overridden.

111. The following feature supports extensibility and reusability of classes
a) function overloading
b) inheritance
c) operator overloading
d) data encapsulation

112. The process of deriving a class from another derived class is
a) single inheritance
b) multilevel inheritance
c) multiple inheritance
d) none of the above

113. When a derived class inherits only from one class and is not further inherited is
a) single inheritance
b) multiple inheritance
c) multilevel inheritance
d) hybrid inheritance

114. When a derived class inherits from may base classes it is
a) multilevel inheritance
b) single inheritance
c) multiple inheritance
d) none of the above

115. Inheritance is ……….. in nature
a) transitive
b) intransitive
c) both (a) & (b)
d) none of the above

116. ……………. variables cannot be declared
a) structure
b) pointer
c) void
d) class

117. When a subclass inherits from multiple base classes, which inherits from a single class, the inheritance type is
a) single inheritance
b) hybrid inheritance
c) multilevel inheritance
d) multiple inheritance

118. When one class inherits from the base class, then the original class is called
a) base class
b) derived class
c) sub class
d) none of the above

119. The default visibility mode while inheriting is
a) private
b) public
c) protected
d) none of the above

120. The class intended to be a base class should use visibility mode as
a) public
b) protected
c) private
d) Both (a) & (b)

121. Operator overloading is
a) making c++ operators work with objects
b) giving c++ operators more than they can handle
c) giving new meaning to existing c++ operators
d) making new c++ operators

122. To convert from a user defined class to a basic type, you would most likely use
a) a built-in conversion function
b) a one-argument constructor
c) an overloaded-operator
d) a conversion function that’s member of the class

123. The members of a class
a) by default are public
b) by default are private
c) are made private by declaring as private
d) none of the above]

124. The following symbol indicates the derived class is derived from the base class
a) ::
b) :
c) ->
d) none of the above

125. When a base class publicly inherited
a) the public members of the base class are inherited as private
b) the private members are inherited as private
c) the protected members are inherited as protected
d) none of the above

126. When a base class is privately inherited by derived class
a) the public members of the base class becomes the private members of the derived class
b) the private members are not inherited
c) the protected members of the base class becomes the private members of the derived class
d) All of the above

127. Only one copy of the class is inherited, when it is defined as
a) virtual
b) static
c) public
d) none of the above

128. A class that acts only as a base class and is not used to create objects is
a) parent class
b) super class
c) abstract class
d) none of the above

129. The version of a virtual function actually gets called during runtime is based solely up in the type of the object that is
a) being instantiated and processed by the function
b) in the derived class
c) being pointed to by a base class pointer
d) being passed to the function

130. In multiple inheritance, the base classes are constructed
a) in the order of declaration in the derived class
b) in the order of declaration in the program.
c) in the order of definition of a class
d) none of the above

131. When an object of a derived class is created
a) derived class constructor is called followed by base class constructor
b) base class constructor is called followed by derived class constructor
c) base class constructor is not called at all
d) none of the above

132. The derived class constructor
a) never passes any values to base class constructor
b) is responsible for passing the entire test of arguments needed by base class constructors
c) can pass arguments only to one base class constructor function
d) none of the above

133. A virtual base class
a) allows to inherit more than one copy of the base class members
b) strict the path of inheritance
c) is qualified as virtual in base class definition
d) none of the above

134. When a base class is inherited publicly
a) the private members of the base class are not accessible
b) the derived class can directly access the private members of the base class
c) the derived class can access the private members only through the member function of the base class
d) none of the above

135. When two or more classes are used within another class definition, it is
a) inheritance
b) aggregation
c) both (a) & (b)
d) none of the above

136. Composition is referred to as
a) “is a” relationship
b) “has a” relationship
c) both (a) & (b)
d) none of the above

137. Inheritance is referred to as
a) “is a” relationship
b) “has a” relationship
c) Both (a) & (b)
d) none of the above

138. An explicitly defined destructor function
a) may be virtual
b) may not be virtual
c) both (a) & (b)
d) None of the above

139. The copy operation by a simple assignment causes in some cases
a) no effect
b) hollow copy
c) copy exactly the same as original
d) creates new

140. Public data members can be accessed
a) only from the base class itself
b) both form the base class and from its derived class
c) from the class which is a friend of the base class
d) none of the above

141. A static automatic variable is used to
a) make a variable visible to several function
b) make a variable visible only to one function
c) converse memory when a function is not executing
d) retain a value when a function is not executing

142. The stacks data structure are based on
a) LIFO
b) FILO
c) FIFO
d) None of the above

143. Queues are based on
a) LIFO
b) FILO
c) FIFO
d) None of the above

144. & operator is
a) indirection operator
b) Logical AND
c) address operator
d) none of the above

145. int *ptr[10]; is
a) an array of 10 int pointers
b) a pointer of 10 int elements
c) an array of 10 elements returning an int value
d) none of the above

146. A structure that refers to itself is a
a) nested structure
b) recursive structure
c) self-referential structure
d) none of the above

147. With in …….scope class member may be referenced simply by their names
a) class’s
b) object’s
c) program
d) none of the above

148. To point to the address of any pointer variable cast the pointer to
a) char *
b) int *
c) void *
d) none of the above

149. Destructors are called
a) in the same order of constructor calls
b) in the reverse order of constructor calls
c) in any random order
d) none of the above

150. The advantage of declaring a virtual function as pure is
a) you can avoid making the class an abstract class
b) you force any derived class to define its own implementation
c) programs runs faster
d) early binding can be achieved

Solution Set to Multiple Choice Questions

(1)         A          (2)         D          (3)         B          (4)         A

(5)         B          (6)         C          (7)         C          (8)         B

(9)         D          (10)       A          (11)       D          (12)       C

(13)       B          (14)       B          (15)       A          (16)       B

(17)       A          (18)       C          (19)       B          (20)       C


(21)       A          (22)       B          (23)       A          (24)       C

(25)       C          (26)       A          (27)       B          (28)       C

(29)       C          (30)       C          (31)       A          (32)       C

(33)       C          (34)       B          (35)       A          (36)       C

(37)       A          (38)       A          (39)       B          (40)       A


(41)       B          (42)       B          (43)       A          (44)       C

(45)       D          (46)       A          (47)       B          (48)       B

(49)       C          (50)       B          (51)       B          (52)       C

(53)       A          (54)       D          (55)       B          (56)       A

(57)       D          (58)       C          (59)       A          (60)       C


(61)       B          (62)       A          (63)       B          (64)       C

(65)       C          (66)       A          (67)       A          (68)       C

(69)       A          (70)       A          (71)       A          (72)       B

(73)       A          (74)       A          (75)       C          (76)       D

(77)       C          (78)       C          (79)       A          (80)       B

(81)       B          (82)       D          (83)       B          (84)       D


(85)       A          (86)       B          (87)       C          (88)       A

(89)       B          (90)       C          (91)       D          (92)       C

(93)       A          (94)       A          (95)       B          (96)       D


(97)       A          (98)       B          (99)       B          (100)      A

(101)      D          (102)      B          (103)      C          (104)      C

(105)      C          (106)      D          (107)      D          (108)      B

(109)      C          (110)      B          (111)      B          (112)      B

(113)      A          (114)      C          (115)      A          (116)      C

(117)      B          (118)      A          (119)      A          (120)      D


(121)      C          (122)      D          (123)      B          (124)      B

(125)      C          (126)      D          (127)      A          (128)      C

(129)      C          (130)      A          (131)      B          (132)      B

(133)      C          (134)      C          (135)      B          (136)      B

(137)      A          (138)      A          (139)      B          (140)      C

(141)      C          (142)      A          (143)      C          (144)      C


(145)      A          (146)      C          (147)      A          (148)      C

(149)      B          (150)      B