C++ MCQ Page 1
1. In POP language the main focus is in ____.
A) Function
B) Object
C) Variable D) Classes
2. Which of the following is an Object Oriented Programming Language?
A) C++
B) C
C) FORTRAN
D) COBOL
3. Which of the following is a Procedure oriented Programming Language.
A) C
B) c++
C) java
D) c#
4. In OOP language the emphasis is on ____.
A) Object
B) Function
C) Classes
D) Variable
5. What is the main benefit of inheritance?
A) Both b and c
B) Reusability
C) Hierarchical Classification
D) None of this
6. c++ was developed by___.
A) Bjarne Stroustrup
B) Steve Joes
C) James Bond
D) Dennis Ritchie
7. Which section of c++ program is the entry point of the program execution?
A) main function
C++ MCQ Page 2
B) Class
C) Object
D) Global declaration Section
8. To run the program is Turbo c++ which short cut key is used?
A) CTRL +F9
B) CTRL + F5
C) CTRL + ALT + F9
D) None of this
9. Function overloading is a feature by which we can achieve ____.
A) Polymorphism
B) Encapsulation
C) Classes
D) Abstraction
10. Wrapping up of data and function into a single unit is known as ____.
A) Encapsulation
B) Namespace
C) Inheritance
D) Data Abstraction
11. _____ is known as Container of classes.
A) Namespace
B) Header File
C) Object
D) Inheritance Classes
12. Which is the symbol of insertion operator?
A) <<
B) >>
C) ?>
D) ;
13. "To save the program in Turbo c++, which short cut key is used?"
A) F2
B) CTRL + F5
C) CTRL + ALT + F9
D) F5
C++ MCQ Page 3
14. Which of the following programming approach used function as a key concept to perform action-
oriented tests?
A) Procedure programming language
B) Object oriented Programming language
C) Modular programming
D) Structure Programming
15. Which of the following is not a token?
A) Loop
B) Identifier
C) Keyword
D) Operator
16. which of the following is a valid identifier ?
A) float
B) amount
C) my name
D) while
17. Size of float data type is ___ bits.
A) 32
B) 4
C) 8
D) 64
18. An unsigned integer variable can store maximum ___ value.
A) 65365
B) 65535
C) 32798
D) 128
19. Which of the following is a user defined data type?
A) Class
B) Array
C) Vector
D) Char
20. Which operator is used to allocate memory allocate to a data object?
A) new
C++ MCQ Page 4
B) delete
C) $
D) *
21. Which operator is used to release memory allocate to a data object?
A) delete
B) *
C) $
D) %
22. "To create an alias of a variable, you can use___ symbol?"
A) &
B) *
C) %
D) ::
23. The symbol of scope resolution operator is ___.
A) ::
B) :
C) ;
D) *
24. "To use the setw manipulator, which header file must be included?"
A) iomanip.h
B) stdlib.h
C) stdio.h
D) iostream.h
25. Which of the following is entry controlled loop?
A) Both b and d
B) For loop
C) Do while loop
D) while loop
26. "In c++, the return type of main function is?"
A) int
B) void
C) integer
D) return
C++ MCQ Page 5
27. The function prototype is also known as ____.
A) Function declaration
B) Function call
C) Function Definition
D) None of this
28. Which symbol is used in call by reference function?
A) &
B) %
C) *
D) ;
29. Which of the following can be in used in inline function?
A) if condition
B) switch condition
C) for loop
D) while loop
30. Which of the following default argument function declaration is invalid?
A) "Double test (int a =5,float b,double c=4.5);"
B) "Void kahani(int a,float b,int c=1);"
C) "Void demo(int a, char b ,int c=2, char d ='a');"
D) "int test(int a=5,int b=20;int c=40);"
31. In case of function overloading which of the following is true?
A) "function names are same, type signatures are different"
B) "function names are different ,type signatures are same"
C) "function names are same , return types are different"
D) "function names are different , return types are same"
32. "If you want to allow to the function to do not change its argument, you can use____."
A) const argument
B) Default argument
C) inline function
D) function overloading
33. Which of the following function part can come more than once in a program?
A) Function call
B) Function definition
C++ MCQ Page 6
C) Function prototype
D) None of this
34. Which of the following function prototype is valid?
A) "void test(int a,float b, float c);
B) “void test(int a,float b float c);"
C) "void test (int a,float b,c);"
D) "void test(int a float a float b,c);"
35. Which of the following is inline function definition is valid?
A) inline double square(int a){return a*a;}
B) inline double square(int a;){return a*a;}
C) inline double square(int a)(return a*a;)
D) None of this
36. Which is the extension of c++ program?
A) .cpp
B) cpp
C) c
D) .c
37. Declaration of class includes ____.
A) Both c and d
B) Return statements of function
C) Declaration of function prototype
D) Declaration of data member
38. The members of structure are ____ by default.
A) Public
B) Private
C) Protected
D) All of this
39. The members of a class are ____ by default.
A) Private
B) Public
C) Both a and b
D) Protected
40. A class defined inside a class is known as _____.
C++ MCQ Page 7
A) Nested class
B) Local class
C) Outer class
D) Parent class
41. A class defined inside a function is known as _____.
A) Local class
B) Outer class
C) Child class
D) Global class
42. A static member variable is initialized to ____ when an object is created of its class.
A) 0
B) NULL
C) 1
D) Random value
43. "Which of the following statement is correct to create the pointer to ""a"" member variable x (type
int) of class Demo?"
A) int Demo::* p = & Demo :: a;
B) int *p = &a;
C) int Demo *p::&p =1;
D) None of this
44. Which of the following statement is correct to access the member variable x(type int) of class demo
using pointer to object ?
A) p->a
B) p::.a
C) p.a
D) p.a*
45. A constructor is a special kind of member function because____.
A) It has same name as its class name
B) it takes parameter
C) it constructs object
D) None of this
46. A Constructor can take parameter.
A) True.
B) False.
C++ MCQ Page 8
C) partially true
D) None of this
47. A destructor can be overloaded.
A) False.
B) True.
C) Both a and b
D) None of this
48. You can only define one constructor in class.
A) False.
B) True.
C) partially true
D) None of this
49. Which of the following is the correct structure of destructor for class ABC?
A) ~ABC(){}
B) ABC{}~()
C) ABC()
D) Delete ~ABC
50. Constructor is invoked when____.
A) Object Initialize
B) Object Destroyed
C) after run the program
D) None of this
51. Which of the following statement does correctly describe the casting operator function?
a) it must not specify return type
b) it must be a class member
c) it must not have any argument
d) all of above
52. Operator overloading is also known by the term _____
a) Runtime polymorphism
b) Compile time polymorphism
C++ MCQ Page 9
c) Both a & b
d) None of above
53. Which of the following operator can be overloaded?
a) sizeof()
b) ?:
c) *
d) ::
54. Which keyword is used to specify an operator overloading function?
a) Operator
b) Overload
c) Overloading
d) Function
55. Overloading a unary operator using member function will require _____ arguments.
a) 0
b) 1
c) 2
d) None of above
56. Overloading a binary operator using friend function will require _____ arguments.
a) 0
b) 1
c) 2
d) None of above
57. Which of the following operator cannot be overloaded using friend function?
a) =
b) ?:
c) ==
d) ::
58. Identify the correct syntax for casting operator function.
A) Operator Data_Type()
{
}
C++ MCQ Page 10
b) Return_Type operator Data_Type()
{
}
c) Return_Type operator Data_Type(arguments)
{
}
e) Operator Data_Type(arguments)
{
}
59. Select the proper syntax to overload unary – operator using friend function.
a) Friend void operator –();
b) Friend void operator –(object);
c) Friend void operator –( object1, object2);
d) Friend operator –();
60. Select the right syntax to overload binary * operator using member function.
a) Void operator *();
b) Void operator *(object );
c) Void operator *(object1,object2 );
d) operator *();
61. Which of the following statement(s) is true , if a derived class is publicly inherited from a base class?
I) The public member of the base class become public member of the derived class
II) The public member of the base class become privete member of the derived class
III) The public member of the base class are inaccessible to the object of the derived
class.
IV) All of the above.
a. I only
b. Both I & II
c. Both I & III
d. IV only
62. Consider the following code segment :
Class A
{
C++ MCQ Page 11
int a;
Public:
int b;
void inp();
}
Class B:A
{
//members of B
}
Which of the following statement(s) is NOT true regarding the above code ?
A) The public member namely ‘b’ and inp() of class A become
privete members of class (B)
B) The public member namely ‘b’ and inp() of class A can be
accessed by the member functions of class B
C) The public member namely ‘b’ and inp() of class A are
inaccessible to the objects of class B.
D) None of the above
63. The benefits of inheritance is ______.
a) Reusability
b) Hierarchical classification
c) Distribution
d) Both A & B
64. If a class is deriving from a derived class ,it is known as ____inheritance
a) Single
b) Multiple
c) Hierarchical
d) Multilevel
65. If a class is deriving from more then one class ,it is known as ____inheritance
A) Single
B) Multiple
C) Hierarchical
D) Multilevel
C++ MCQ Page 12
66. Which of the following visibility modifier is has the lowest visibility?
A) Public
B) Private
C) Protected
D) Default
67. In which type of inheritance one class derived from more than one base class?
A) Multilevel inheritance
B) Multiple inheritance
C) Hierarchical inheritance
D) All of the above
68. Which of the following is default visibility modifier in c++?
A) Public
B) Private
C) Protected
D) None of the above
69. The protected members can be accessed ____
A) Within same class
B) In all classes of current program
C) In the same class and in the derived class
D) In the same class and in the main function.
70. Which of the following statement(s) is true according to the following statement?
P=*ptr;
a) P must be a pointer variable
b) The value of ptr is assign to the variable p
c) The address of the pointer ptr assign to the pointer variable p
d) The value of the variable that the pointer ptr is pointing to is assign to the variable p
71. The virtual function should be declare in ____ class.
a) Base class
b) Derived class
c) Both base & derived class
d) None of these
72. Which of the following statement(s) is true?
C++ MCQ Page 13
I. A base class pointer can point to derived class object
II. A base class pointer can point to base class object
III. A derived class pointer can point to derived class object
IV. A derived class pointer can point to base class object
a) Only IV
b) Only I & III
c) Only I , II & III
d) Only II , III & IV
73. Which of the following statement about virtual function is false?
a) A virtual function cannot be a member function of a class
b) A virtual function cannot be static member
c) A virtual function can be accessed by base class pointer.
d) A virtual function can be friend of another class
74. Which of the following definition for pure virtual function is false?
a) virtual void test()=0;
b) virtual void test(int a=10)=0;
c) virtual int test()=0;
d) virtual void test();
75. What is the full form of RTTI?
a) Real Time Type Information
b) Real Time Task Identifier
c) Runtime Type Identification
d) Runtime Type Interpretation
76. If the name & prototype of functions in both the base class & derived class are same, then which
version of the function will be called by the derived class object.?
a) Base class
b) Derived class
c) Both base & derived class
d) Either base or derived class
77. What would be the output of the following code?
cout.fill(‘$’);
cout.setf(ios::left,ios::adjustfield );
C++ MCQ Page 14
cout.width(20);
cout<<”i/o operation ”;
a) Operations$$$
b) i/o operation
c) i/o operations$$$$$$
d) i/o operations$$$$$$$
78. which class is the base class of iostream class?
a) istream
b) ostream
c) streambuf
d) Both a& b
79. What would be the output of the following code?
int a=56.789;
cout<<setprecision(1)<<a;
a) 56.1
b) 56.7
c) 56.8
d) 56.78
80. Which flag is used to specify hexadecimal no. format?
a) ios::basefield
b) ios:: hex
c) ios::hexa
d) ios:: base
81. Identify the correct statement for setting scientific notation ?
a) cout.setf(ios::scientific,ios::floatfield) ;
b) cout.setf(ios::floatfield,ios::scientific);
c) cout.setf(ios::scientific);
d) cout.setf(ios::scientific,ios::basefield );
82. Identify the correct statement for setting internal alignment using manipulator ?
a) cout<<setiosflags(ios::internal,ios::adjustfield);
b) cout<<setiosflags(ios::internal);
c) cout<<setf(ios::internal);
d) cout<<setf(ios::internal,ios::adjustfield);
C++ MCQ Page 15
83. Whiich of the following function(s) oprens a file named “sample” for writing only?
a. ofstream_object.open(“sample”,ios::app);
b. ifstream_object.open(“sample”,ios::out);
c. ofstream_object.open(“sample”,ios::out);
d. ifstream_object.open(“sample”,ios::app);
84. which of the following line(s) opens a file “test.txt” in input mode?
a. Ifstream f(“test.txt”);
b. Ifstream f;
f.open(“test.txt”);
c. fstream f;
f.open(“test.txt”,ios::in);
d. all of the above
85. which of the following file modes does not allow writing data in the filw?
a. ios::app
b. ios::out
c. ios::in
d. ios::ate
86. which function is used to find the current position of the output pointer?
a) seekg()
b) tellg()
c) tellp()
d) seekp()
87. which of the following statement will move the input pointer to the 10th character in a 100 character
file?
a) fileobj.seekg(10,ios::cur);
b) fileobj.seekg(10,ios::end);
C++ MCQ Page 16
c) fileobj.seekg(90,ios::beg);
d) fileobj.seekg(-90,ios::end);
88. Which of the following is not the error handling function?
a) fail()
b) good()
c) read()
d) eof()
89. Which of the following function is used to write objects into a file?
a) put()
b) write()
c) et()
d) writeobject()
90. Identify the syntax of main() function to pass command line argument .
a) int main()
b) int main(int n, int *a[])
c) int main(char n,char *a[])
d) int main(int n,char *a[])
91. Which symbol is used to specify more than one file modes in open function?
a) &(and)
b) | (or)
c) + (plus)
d) , (comma)
92. Which Block handles the exception?
a. Finally block
b. Catch block
c. Try block
d. None of the above
93. Which of the following keyword is used to report an exception?
a. Try
b. Catch
c. Throw
d. All of the above
94. Which of the following symbol is used to catch all type of exception?
C++ MCQ Page 17
a. catch(all exception)
b. catch(::)
c. catch(*)
d. catch(…)
95. Write the syntax to specify the int & char type exception for function abc().
a. void abc() throw int , char
b. void abc() throw (int),(char)
c. void abc() throw (int , char)
d. void abc() throw int char
96. What happens if the program generates an exception and it is not handled?
a. The program gives wrong output
b. The program is terminated as the exception is generated
c. The compiler reports about the exception and the program continues.
d. None of these
97. If an exception is not caught, then it is ignored.
a. True
b. False
98. Using exception handling, you can also detect syntax error in the program.
a. True
b. False
99. An exception can be generated by ____
a. A syntax error
b. A logical error
c. Hardware problem
d. A runtime error
100. Consider the following code segment:
template <class temp>
Class sample
{
//code
C++ MCQ Page 18
};
Identify the correct syntax for declaring a dynamic array of character using the above template .
a. sample <char> characterArray;
b. sample <datatype> characterArray;
c. temp <char> characterArray;
d. temp <datatype> characterArray;
101. In the following template declaration, Temp stands for _______
a. An integer data type
b. A class name
c. A generic data type
d. A predefined class
102. What is syntax to declare a class template of one parameter?
a. class <template T>
b. template <class T>
c. template <T>
d. class <T>
103. Identify the correct template definition.
1) Template <class T>
Class test
{
//class definition
};
2) Template <class X,Y>
Class test
{
//class definition
};
3) Template <class X, int a>
C++ MCQ Page 19
Class test
{
//class definition
};
4) Template <class X,Y,int a>
Class test
{
//class definition
};
a. 1
b. 2
c. 1 and 2
d. 1 and 3
104. Full form of STL is ____
a. Special Template List
b. Standard Template List
c. Standard Template Library
d. Special Template Library
105. Which of the following is not a component of STL?
a. Templates
b. Containers
c. Iterators
d. Algorithms
106. Which function is used to delete the last element of the vector?
a. erase()
b. delete_last()
c. pop()
d. pop_back()
107. Which function is used to delete all the elements of the vector?
a. erase_all()
b. remove_all()
C++ MCQ Page 20
c. clear_all()
d. clear()
108. If a template function is overloaded, then which version will be called first when the function is
called?
a. Ordinary function
b. Template function
c. Whichever is created first
109. Which of the following container follows LIFO approach to insert and delete elements?
a. Vector
b. List
c. Stack
d. Queue
Top Related