Sie sind auf Seite 1von 16

Kondapalli.

SrinivasaRao
1
C++ QUESTION

Chapter: 1
1.What do u mean by programming methodology?
Ans: it is a method by which we are dividing the programs.

2.What are the types of programming methodology?
Ans: it is mainly of 2 types:
a) object oriented programming ( OOPs)
b) procedure oriented programming ( POPs)
3.What is the difference between oop & pop?
Ans: Difference is given below:
a) In oop, program is divided into objects. But in pop, program is divided
into function.
b) Oop follows bottom-up approach. But Pop follows top-down approach.
c) In oop, data may be declared as private, public or protected. But in
pop, datas are always declared as global.
d) In oop, data hiding concept is found. So data is secured. But in pop,
data hiding concept is not found. So data is not secured.
e) Ex of oops are c++, java, Smalltalk, Eiffel, charm++. But ex of pop are
c, fortan, COBOL, basic.
4.What are the basic oops concept?
Ans: Basic oops concepts are class, object, data abstraction, encapsulation,
inheritance, polymorphism, message passing
5.What is the access specifier available in c++?
Ans: There are 3 types of access specifier is present. These are private, public &
protected.
6.What do u mean by data hiding concept?
Ans: if we declare the data as private, it can only access by the function of that class
only. Other functions can not access the data. It is called data hiding.
7.What do u mean by message passing?
Ans: due to message passing, the objects can communicate with each other.
8.Define object in terms of class?
Ans: object is a variable of class type.
9.Write some oops language?
Ans: c++, java, Smalltalk, Eiffel.
10. What is the advantage of oop?
Ans: advantage is given below:
a) Using inheritance, redundancy can be avoided.
b) Software complexity can be easily managed.
c) Due to data hiding concept, data is much secured.

Chapter: 2
11. Who developed c++?
Ans: Bjarne Strousstrup developed c++ at AT & T Bell lab in the year 1980.
12. What is the reason behind the development of c++?
Ans: To avoid the problem i.e occurred in c, a new language is developed called c++.
Kondapalli.SrinivasaRao
2
The problems are:
a) Datas are declared as global. So data is not secured.
b) In c, program is divided into function. So every function can access the
data. If program is large, then it is very difficult to know which
function can access which data.
13. What is the use of #include<iostream>?
Ans: it is a preprocessor directive that instructs the compiler to add the file into source
code. Iostream means input, output stream. Input stream takes the input from
keyboard. Output stream shows the output.
14. What is the use of main ( ) in a program?
Ans: it is the main part in the program where the execution begins.
15. What is the difference between input stream & output stream?
Ans: Input stream takes the input from keyboard. Output stream shows the output.
16. How to create, compile & run the file in Linux environment?
Ans:
a) Create : vi file name.cpp
b) Compile: c++ file name. cpp
c) Run: . / a. out
17. What is the use of namespace STD in ++ program?
Ans: it is a scope for identifier. STD is a namespace that contains all the class
libraries.
Chapter: 3
18. What do u mean by token?
Ans: Token is the smallest individual unit in a program.
19. What are the types of token available in c++?
Ans: C++ contains these tokens: keyword, identifiers, constant, string, operator.
20. How many keywords are used in c++?
Ans: Keywords are reserved set of words with fixed meaning. There are 63 keywords
in c++. Keywords are: auto, break, case, char, default, do, enum, for, friend etc.
21. What are the types of data type?
Ans: Data type is mainly divided into 3 types: user defined, fundamental, and derived.
a) User defined data type includes: class, structure, union, enum.
b) Derived data type includes: array, function, pointer, reference.
c) Fundamental data type includes: int, float, double, char
22. What is the use of void data type?
Ans: Void data type is used for following purpose.
a) It acts as a generic pointer.
b) It specifies the return type.
c) It is also used as a argument for the function.
23. What is the difference between array & structure?
Ans: Array is a collection of similar data type where as structure is a collection of
dissimilar data type. Array is a derived data type where structure is a user defined
data type.
24. What is the difference between structure in c & c++?
Ans: Structure in c contains only data members. But structure in c++ contains data
member & functions.
25. What is the difference between structure & class in c++?
Kondapalli.SrinivasaRao
3
Ans: In C structure data members are by default public. But in C++ structure data
members are by default private. C structure does not support the oops concept. But
c++ structure supports the oops concept.
Kondapalli.SrinivasaRao
4
26. What is the difference between structure & union?
Ans: In structure, the entire member has its own memory location. But in union all the
members share the memory location.
27. What is the use of reference data type?
Ans: it provides an alternative name for previously defined variable.
Syntax: int a =10;
Int &b=a;
28. What do u mean by anonymous union?
Ans: The union that does not contain any tag name.
Ex: union
{
Int a;
Float j;
}
29. What are the built in data type available in c++?
Ans: Int, char, double, float.
30. What is the use of scope resolution operator?
Ans: it is mainly used to access the global variable.
31. What are the memory management operators available in c++?
Ans: New & Delete operator.
32. What is the use of new & delete operator?
Ans: New operator is used to allocate the memory. Delete is used to deallocate the
memory.
33. What is the difference between new & malloc?
Ans: Difference is given below:
a) New is a operator i.e. used in c++. But malloc is a function used in c.
b) New creates the object & also allocate the memory. But malloc
function only allocates the memory.
c) New can be overloaded. But malloc can not be overloaded.
34. What is the use of insertion & extraction operator?
Ans: Insertion operator displays the output on the screen.
Extraction operator extracts the value from the keyboard.
Chapter: 4,
35. What do u mean by class?
Ans: class is a collection of data & member function.
36. What is the syntax of class?
Ans: class <class name >
{
Data member declaration;
Member function declaration;
}
37. How to define the member function in a class?
Ans: The function that is enclosed in a class is called is called member function.
38. What is the difference between function & member function?
Ans: Function is a block of statements that perform some task. But the function that is
enclosed in a class is called is called member function.
39. What are the steps in class program?
Ans:
Kondapalli.SrinivasaRao
5
a) Declare a class.
b) Declare the data member & member function in side the class.
c) Define the member function inside or outside the class.
d) Declare the main program.
e) Create the object inside the class.
f) Access the member function using the object.
40. What is the difference between private, public & protected?
Ans:
Private: if we declare the data as private, it can only access by the function of that
class only.
Public: if we declare the data as public, it can access by the function of all classes.
Protected: if we declare the data as protected, it can only access by the function of the
sub class only.
41. What do u mean by static data member?
Ans: If we declare the data as static then its value will remain constant during the
program.
42. What are the properties of static data member?
Ans: Properties is given below:
a) It can be shared by the entire object.
b) By default its value is initialized to zero.
c) Its value will remain constant.
d) It must be initialized outside the class.
e) It uses the keyword static.
43. What do u mean by static member function?
Ans:
a) It can only access the static data member.
b) It can be invoked using class name instead of object name.
44. What is the use of static object?
Ans: Static object initializes all the data member to zero.
45. What is constant member function?
Ans: It can not modify any data member in the class.
46. How to access the private member function in a class?
Ans: When we declare the member function as private, then it can be accessed in side
the public member function. Object can not invoke the private member function.
47. Why array of object is used?
Ans: To display the output of more than one object we can use the array of object
concept.
48. Difference between local class & global class?
Ans: Difference between this is given below:
a) The class i.e. declared outside the main function is called global class.
But the class i.e. declared inside the main function is called local class.
b) Local class has only local object. But global class has both local &
global object.
c) Local class can not have static data member & member function. But
global class has static data & static member function.
49. What do u mean by empty class?
Ans: The class without any data member & member function is known as empty
class.
Kondapalli.SrinivasaRao
6
50. What is the use of empty class?
Ans: It is generally used in exception handling program.
51. What is const argument?
Ans: When we declare the data as constant, its value remain constant.
Chapter: 5
52. What do u mean by function?
Ans: it is a block of statements that perform some tasks
53. What is the need of function?
Ans: function is used for following purpose:
a) Using function, large program can be divided into smaller ones. It is
easy to debug & find out the errors in it.
b) If we want to perform task repetitively, it is not necessary to rewrite
the particular block of statements again & again. Shift the particular
block of statement in a user defined function.
54. What is function prototype?
Ans: it is a declaration statement in a program.
Syntax: return type function name (argument);
Ex: voids add (int, int);
55. What is the function arguments used in c++?
Ans: There are 2 types of arguments are used in c++.
a) Actual argument: argument of calling function.
b) Formal argument: argument of called function.
56. How to pass the parameters in function?
Ans: it can be possible in 3 ways:
a) call by value( pass by value)
b) call by reference ( pass by reference)
c) call by address( pass by address)
57. What is inline function?
Ans: By default all the functions defined inside the class is called inline. If we want to
make the function outside the class as inline, then inline keyword is used.
58. What is the advantage of inline function?
Ans: Execution is very first.
59. What is the disadvantage of inline function?
Ans: It takes more memory space.
60. What are the rules for inline function?
Ans: It has following rules:
a) Inline function is used when the program contains few statements.
b) Recursion function can not be inline.
c) Main ( ) function can not be work as inline.
d) It should not contain static variable.
e) Function containing go to, for, switch can not be inline.
61. What is the difference between inline & macro?
Ans: Difference between inline & macro is given below:
a) In inline function when the function is called the code of the function
is replaced with the function call. But in macro only the value is
replaced.
b) In inline function, error is checked during execution. But in macro
error is not checked.
Kondapalli.SrinivasaRao
7
62. What is the difference between open subroutine & close sub routine?
Ans: Inline function is called open sub routine but normal function is called close sub
routine. Difference is given below.
63. What is the difference between inline function & function?
Ans: Difference between inline function & function is given below:
a) In general function when we call the function the control goes to the
function definition & then it comes to the each statement in the
function definition; finally the control comes to the main program. But
in inline function when the function is called the code of the function is
replaced with the function call
b) General function takes less memory space where inline function takes
more memory space.
c) In function, execution speed is less but in inline function execution is
very first.
64. What is function overloading?
Ans: functions having same name but different arguments are called function
overloading.
65. What is the difference between function overloading & function overridden?
Ans: functions having same name but different arguments are called function
overloading.
But in function overridden, if the base class & derived class have
same function name & function parameter, then function in derived class is said to
override the function or method in the base class.
66. What is the use of friend function?
Ans: Due to data hiding concept, non member functions can not access the private
data. So to access this, c++ provides a new concept called friend function. If we
declare the function as a friend of other class, then it can access the private data.
67. What are rules for friend function?
Ans:
a) The friend key word is used.
b) In function declaration, class name is given in place of argument.
c) In function definition, object is created in place of function argument
d) It can be accessed using the object name.
68. What is friend class?
Ans: It is possible to declare the whole class as friend. It is known as friend class.
69. How to calculate the size of object?
Ans: Size of object is equal to the sum of the size of all class data member of the
class.
70. What are the library functions?
Ans: in c++, mainly 4 library functions are used: ceil ceill, floor, and floorl.
71. How to round up & round down the float number?
Ans: float number can be round up using ceil & ceill library function. But float
number can be round down using floor & floorl library function.
Chapter: 6
72. What do u mean by constructor?
Ans: it is a special member function which is used to initialize the object of a class
when the object is created. It is called constructor because it constructs the value of
the data member.
Kondapalli.SrinivasaRao
8
73. What are the properties of constructor?
Ans: properties of constructor are given below:
a) It is used to initialize the object when the object is created.
b) Its name is same as class name.
c) It has no return type.
d) It should be declared in public part.
e) It can be overloaded.
f) It can not be inherited.
g) It can not be virtual.
74. What are the types of constructor?
Ans: it is mainly of 5 types:
a) Default constructor.
b) Parameterized constructor.
c) Copy constructor.
d) Default argument constructor.
e) Dynamic constructor.
75. What is the use of default argument constructor?
Ans: Parameterized constructor having default value is called default argument
constructor.
76. What is dynamic constructor?
Ans: The constructor can also be used to allocate the memory while creating the
object. It is called dynamic constructor. It will enable the system to allocate the right
amount of memory.
77. What is the difference between shallow copy & deep copy?
Ans:
78. What is destructor?
Ans: Destructor is used to destroy the object i.e. created by constructor.
79. What are the properties of destructor?
Ans: a) its name is same as class name.
b) It has no return type.
c) It is same as class name only proceeding by a symbol tilde i.e. ~.
d) It can not be overloaded.
e) It can be virtual.
f) It never takes any argument.
g) In a program only one destructor is present.
80. What is the difference between constructor & destructor?
Ans: Difference is given below:
a) Constructor is used to construct the value of data member. But
destructor is used to destroy the value of data member i.e. created by
constructor.
b) Constructor can be overloaded but destructors can not be overloaded.
c) Constructor can not be virtual but destructor can be.
d) Constructor can be called implicitly or explicitly.
81. What is const object?
Ans: We can make the object constant by the keyword const. It can only access the
constant member function.
82. What is anonymous object?
Kondapalli.SrinivasaRao
9
Ans: it is possible to create the object without the name & such objects are called
anonymous object. It is only possible in constructor.
83. What is the difference between local & global object?
Ans: when the object is declared inside the main function it is called local object. But
the object i.e. defined outside the main function is called global object.
84. How to use the private constructor?
Ans: when the constructor is declared as private, it can be invoked through the public
member of the class.
Kondapalli.SrinivasaRao
10
Chapter: 7
85. What is inheritance?
Ans: In inheritance a new class is created from the existing one. The existing class is
called parent/ super/ base class. The new class is called child/ sub/ derived class.
86. What do u mean by reusability?
Ans: Derived class reuses the property of base class. It is called reusability.
87. What are the types of inheritance?
Ans: there are 5 types of inheritance:
a) Single inheritance.
b) Multiple inheritances.
c) Multilevel inheritance.
d) Hierchical inheritance.
e) Hybrid inheritance.
88. What is the difference between multiple & multilevel inheritance?
Ans: In multiple inheritances, a new class is derived from more than one base class.
But in multilevel inheritance, a new class is derived from a derived class i.e. derived
from another base class.
89. What is the use of virtual base class?
Ans: To overcome the ambiguity that is occurred in multipath inheritance c++
provides a new keyword that is virtual. If we declare the base class as virtual, then the
compiler takes necessary steps avoid the duplication of member variable.
90. What is delegation?
Ans: Declaring the object as a class data member in another class is known as
delegation.
91. What is containership?
Ans: When a class has an object of another class as its data member, the class is called
container class & the relationship between two classes is known as containership.
92. What is abstract class?
Ans: When a class is not used for creating an object, it is called as abstract class. It
only acts as a base class.
93. What is common constructor?
Ans: We know constructor can not be inherited. When a class is derived from another
class, it is possible to define constructor in derived class. Data member of both base &
derived class can be initialized using derived class constructor. Thus the constructor
of derived class works for its base class. Such constructors are known as common
constructor.
94. What is the difference between public & private inheritance?
Ans: when a class is derived publicly, all the public members of base class can be
accessed directly in the derived class.
But in private inheritance, the public member of base class can be accessed
using public function of derived class.
95. What is the advantage of inheritance?
Ans:
a) Inheritance provides reuse of code. So no need to write the code again
& again.
b) By reusability, the development time of software is reduced.
96. What is the disadvantage of inheritance?
Kondapalli.SrinivasaRao
11
Ans: In class hierarchy, various data elements remain unused. The memory allocated
to them is not utilized.
Kondapalli.SrinivasaRao
12
97. What do u mean by function overloading in inheritance?
Ans: If function overloading occurs in inheritance, then using scope resolution
operator, base class member function can be accessed
Chapter: 8
98. What is operator overloading?
Ans: Operator is a symbol that performs on constant & variable. But it can not operate
on object. Thats why c++ provides a new concept by which operators are providing
extra task i.e. operate on objects. It is called operator overloading.
99. What is the advantage of operator overloading?
Ans: using operator overloading, it can acts on the objects.
100. How to overload the operator?
Ans: Either using member function or friend function.
101. How many arguments are used for unary & binary operator overloading?
Ans:
Unary: using member function 0 arguments & using friend function 1 argument.
Binary: using member function 1arguments & using friend function 2 arguments.
102. Which operators can not be overloaded?
Ans: scope resolution operator (::), size of operator (size of ( )), dot operator (.),
pointer to member operator (. *), ternary operator (? :)
103. Which operators cant be overloaded using friend function?
Ans: function call operator, subscript operator, assignment operator, class member
access operator
104. What is the return type of operator function?
Ans: Class type
105. What are the types of conversion?
Ans: There are 3 types of conversion:
Basic to class type conversion.
Class to basic type conversion.
Class to class type conversion.
106. What is the difference between basic to class & class to basic type
Conversion?
Ans: While converting from basic to class type, the conversion function should be
defined in terms of constructor. But while converting from class to basic type, the
conversion function should be defined in terms of operator function.
Chapter: 9
107. What do u mean by polymorphism?
Ans: poly means many & morphism means forms. So polymorphism means one name
having different forms.
108. What are the types of polymorphism?
Ans: 2 types of polymorphism i.e. compile time & run time.
109. What the difference is between compile & run time polymorphism?
Ans: Difference between compile time & run time polymorphism is given below:
In compile time polymorphism an appropriate member function is selected
during compile time. But in run time polymorphism an appropriate
member function is selected during run time.
Compile time polymorphism includes function overloading & operator
overloading. Run time polymorphism includes virtual function
Kondapalli.SrinivasaRao
13
Compile time polymorphism is called early or static binding. But run time
polymorphism is called late or dynamic binding.

110. What do u mean by virtual function?
Ans: When the function in both base & derived class has same name, then the
function in base class is said to be virtual using virtual keyword.
111. What is the difference between base class pointer & derived class pointer?
Ans: Base class pointer points to both base & derived class object. But derived class
pointer points to only the object of derived class.
112. What are the rules for virtual function?
Ans: Rules are given below:
Constructor can not be virtual but destructor can be virtual.
Virtual function can be invoked using object pointer.
Virtual function may be declared as friend for another class.
113. What is pure virtual function?
Ans: Virtual function i.e. equated to zero is called pure virtual function.
114. What is abstract class?
Ans: A class that contains pure virtual function is called abstract class.
Chapter: 10
115. What is generic programming?
Ans: The program that supports generic class & generic function is called generic
programming.
116. What is the difference between generic class & generic function?
Ans: A class that works for all data types is known as class template. But a function
that works for all data type is known as function template.
117. What is template?
Ans: Template supports generic programming.
118. What is the need of template?
Ans: advantage of template is given below:
Program size is decreased.
Less number of local variables is declared.
Time complexity is less.
119. What is the difference between function overloading & template?
Ans: Difference is given below:
In function overloading more number of local variables are declared but
in template less number of local variables are declared.
In function overloading program size is large but in template function
size will decrease.
120. What are the types of template?
Ans: 2 types i.e. class template & function template.
121. Write the syntax of class template & function template?
Ans: Function template syntax:
Template<class T>
Return type function name (template type argument)
{
}
Class template syntax:
Template<class T>
Kondapalli.SrinivasaRao
14
Class class name
{
};


122. What is the difference between class template & template class?
Ans: A class that works for all data type is known as class template. But when a class
is derived class template, it is known as template class.
123. What is the difference between function template & template function?
Ans: A function that works for all data type is known as function template. But when
a function is derived from function template is known as template function.
124. What is the difference between template & macro?
Ans: Difference is given below:
Template is used for all the data types. But macro is only used for
replacement of value.
In template error is checked during compilation. But in macro error is
not checked.
Chapter: 11
125. What do u mean by error in a program?
Ans: Error is a condition that does not allow a program to execute or run.
126. What are the types of error available in c++?
Ans: 2 types of errors are available: compile time & run time error.
127. What the difference is between compile time & run time error?
Ans: Difference is given below:
In compile time error, error is checked during compilation. But in run
time error, error is checked during run time.
Example of Compile time error is missing of semicolon, missing of
brackets, undeclared identifier. Example of run time error is division
by zero & array out of range.
Compile time error is also known as syntax error. But run time error is
known as logical error.
128. What is exception?
Ans: Exception is a run time error.
129. What are the types of exception?
Ans: Exception is of two types: synchronous & asynchronous.
130. How to handle the exception in c++?
Ans: C++ only handles the synchronous exception. To handle the exception,
exception handling mechanism is used. It is built upon 3 keywords i.e. try, throw &
catch. Try: exception is generated here.
Throw: exception is thrown using throw statement.
Catch: thrown exception is caught using catch statement.
131. How to handle the uncaught exception?
Ans: uncaught exception can be handled using following functions: terminate ( ), set
terminate ( ) & abort ( ) function.
Chapter: 12
132. What do u mean by file?
Ans: File is a collection of related data stored in a particular area on the disk.
133. Why file is not stored in primary memory?
Kondapalli.SrinivasaRao
15
Ans: Primary memory is volatile. So file is not stored here.
134. How to open a file?
Ans: File can be opened in 2 ways:
Using constructor.
Using member function open ( ).


135. What classes used for file operation?
Ans: if stream: read operation
Of stream: write operation
Fstream: both read & write operation.
136. What are the file opening modes?
Ans: Different file opening modes are given below:
Ios::in: used for read purpose.
Ios::out: used for write purpose.
Ios:: app: add at the end.
Ios:: ate : modify & add.
Ios:: trunc: makes the file to zero length.
Ios:: binary: opens the file in binary mode.
Ios:: no create : open fails if the file does not exist.
Ios:: no replace : open fails if the file already exists.
137. What are the file pointers?
Ans: There are two file pointers: get & put pointer.
138. What are the file pointer handling function?
Ans: seekp ( ), seekg ( ), tellp ( ), tellg ( )
139. What is the difference between binary & text mode in a file?
Ans: Suppose we want to enter the data int a=123, then in binary mode it will take 2
byte because int requires 2 byte. But in text mode it will take 3 byte , one for each
digit.
140. How to find the end of a file?
Ans: To find the end of a file, eof ( ) function is used.
141. How to check the error in a file?
Ans: The logical negation operator (!) is used to check the error in a file. It can be
used with the object of file stream class.
142. What do u mean by command line argument?
Ans: When some argument is associated with command, these are called command
line argument. It is used with function main ( ).
Syntax:
Main (int argc, char argv [ ])
143. How to handle the error during file operation?
Ans: using error handling functions & these are eof ( ), bad ( ), good ( ), fail ( ).
Chapter: 13
144. What do u mean by STL?
Ans: it is an advance application of template. It contains several in built function &
operators that help the programmer to develop complex program. The programmer
needs to include the header file to use the function or operator like library function.
145. What is the container of STL?
Kondapalli.SrinivasaRao
16
Ans: It includes mainly 3 components:
Container
Algorithm
Iterator.
146. Give an example that will show all the STL components?
Ans: computer: container
Icons on computer: algorithm
Cursor: Iterator.

147. What is container? What are the types of container?
Ans: container is an object that contains all the data or other objects.
It is of 3 types.
Associative container: it includes set, multi set, map & multi map.
Sequence container: It includes vector, deque & list.
Derived container: it includes stack, queue & priority
148. What do u mean by algorithm & iterator?
Ans: Algotithms are the application that is used to carry out the operation on the
content. But iterators behave like pointers & used to access the element of container.
149. What is the difference between vector & array?
Ans: Array is a collection of similar data types. In array size is fixed. We cant enter
more element than the size given. But vector is a dynamic array. We can add any no
of element. Suppose given dynamic int a [12]. If we want to enter 14 elements then it
can be possible. Automatically the size of array will be increased.
150. What do u mean by smart pointer?
Ans: Iterators are called as smart pointer. They are used by the algorithm to carry
operations.
151. What is the use of list?
Ans: list allows the insertion & deletion of item anywhere. It can be accessed
bidirectional. It is defined in the header file <list>.




If you have any doubts and need material mail me on below e-mail:

Kodapalli.srinu007@gmail.com

Das könnte Ihnen auch gefallen