Answer C++

You might also like

You are on page 1of 13

C++ QUESTION

Chapter: 1
1. What do u mean by programming methodology
Ans: it is a method by which we are dividing the programs.
!. What are the type" o# programming methodology
Ans: it is mainly of 2 types:
a) object oriented programming ( OOPs)
b) procedure oriented programming ( POPs)
$. What i" the di##eren%e bet&een oop ' pop
Ans: ifference is given below:
a) !n oop" program is divided into objects. #ut in pop" program is divided
into function.
b) Oop follows bottom$up approach. #ut Pop follows top$down approach.
c) !n oop" data may be declared as private" public or protected. #ut in
pop" datas are always declared as global.
d) !n oop" data hiding concept is found. %o data is secured. #ut in pop"
data hiding concept is not found. %o data is not secured.
e) &' of oops are c((" java" %malltal)" &iffel" charm((. #ut e' of pop are
c" fortan" *O#O+" basic.
(. What are the ba"i% oop" %on%ept
Ans: #asic oops concepts are class" object" data abstraction" encapsulation"
inheritance" polymorphism" message passing
). What i" the a%%e"" "pe%i#ier a*ailable in %++
Ans: ,here are - types of access specifier is present. ,hese are private" public .
protected.
+. What do u mean by data hiding %on%ept
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. !t is called data hiding.
,. What do u mean by me""age pa""ing
Ans: due to message passing" the objects can communicate with each other.
-. .e#ine ob/e%t in term" o# %la""
Ans: object is a variable of class type.
0. Write "ome oop" language
Ans: c((" java" %malltal)" &iffel.
11. What i" the ad*antage o# oop
Ans: advantage is given below:
a) /sing inheritance" redundancy can be avoided.
b) %oftware comple'ity can be easily managed.
c) ue to data hiding concept" data is much secured.
Chapter: !
11. Who de*eloped %++
Ans: #jarne %trousstrup developed c(( at A, . , #ell lab in the year 0123.
1!. What i" the rea"on behind the de*elopment o# %++
Ans: ,o avoid the problem i.e occurred in c" a new language is developed called c((.
,he problems are:
a) atas are declared as global. %o data is not secured.
0
b) !n c" program is divided into function. %o every function can access the
data. !f program is large" then it is very difficult to )now which
function can access which data.
1$. What i" the u"e o# 2in%lude3io"tream4
Ans: it is a preprocessor directive that instructs the compiler to add the file into source
code. !ostream means input" output stream. !nput stream ta)es the input from
)eyboard. Output stream shows the output.
1(. What i" the u"e o# main 5 6 in a program
Ans: it is the main part in the program where the e'ecution begins.
1). What i" the di##eren%e bet&een input "tream ' output "tream
Ans: !nput stream ta)es the input from )eyboard. Output stream shows the output.
1+. 7o& to %reate8 %ompile ' run the #ile in 9inu: en*ironment
Ans:
a) *reate : vi file name.cpp
b) *ompile: c(( file name. cpp
c) 4un: . 5 a. out
1,. What i" the u"e o# name"pa%e ST. in ++ program
Ans: it is a scope for identifier. %, is a namespace that contains all the class
libraries.
Chapter: $
1-. What do u mean by to;en
Ans: ,o)en is the smallest individual unit in a program.
10. What are the type" o# to;en a*ailable in %++
Ans: *(( contains these to)ens: )eyword" identifiers" constant" string" operator.
!1. 7o& many ;ey&ord" are u"ed in %++
Ans: 6eywords are reserved set of words with fi'ed meaning. ,here are 7- )eywords
in c((. 6eywords are: auto" brea)" case" char" default" do" enum" for" friend etc.
!1. What are the type" o# data type
Ans: ata type is mainly divided into - types: user defined" fundamental" and derived.
a) /ser defined data type includes: class" structure" union" enum.
b) erived data type includes: array" function" pointer" reference.
c) 8undamental data type includes: int" float" double" char
!!. What i" the u"e o# *oid data type
Ans: 9oid data type is used for following purpose.
a) !t acts as a generic pointer.
b) !t specifies the return type.
c) !t is also used as a argument for the function.
!$. What i" the di##eren%e bet&een array ' "tru%ture
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.
!(. What i" the di##eren%e bet&een "tru%ture in % ' %++
Ans: %tructure in c contains only data members. #ut structure in c(( contains data
member . functions.
!). What i" the di##eren%e bet&een "tru%ture ' %la"" in %++
Ans: !n * structure data members are by default public. #ut in *(( structure data
members are by default private. * structure does not support the oops concept. #ut c(
( structure supports the oops concept.
2
!+. What i" the di##eren%e bet&een "tru%ture ' union
Ans: !n structure" the entire member has its own memory location. #ut in union all the
members share the memory location.
!,. What i" the u"e o# re#eren%e data type
Ans: it provides an alternative name for previously defined variable.
%ynta': int a :03;
!nt .b:a;
!-. What do u mean by anonymou" union
Ans: ,he union that does not contain any tag name.
&': union
<
!nt a;
8loat j;
=
!0. What are the built in data type a*ailable in %++
Ans: !nt" char" double" float.
$1. What i" the u"e o# "%ope re"olution operator
Ans: it is mainly used to access the global variable.
$1. What are the memory management operator" a*ailable in %++
Ans: >ew . elete operator.
$!. What i" the u"e o# ne& ' delete operator
Ans: >ew operator is used to allocate the memory. elete is used to deallocate the
memory.
$$. What i" the di##eren%e bet&een ne& ' mallo%
Ans: ifference is given below:
a) >ew is a operator i.e. used in c((. #ut malloc is a function used in c.
b) >ew creates the object . also allocate the memory. #ut malloc
function only allocates the memory.
c) >ew can be overloaded. #ut malloc can not be overloaded.
$(. What i" the u"e o# in"ertion ' e:tra%tion operator
Ans: !nsertion operator displays the output on the screen.
&'traction operator e'tracts the value from the )eyboard.
Chapter: (8
$). What do u mean by %la""
Ans: class is a collection of data . member function.
$+. What i" the "ynta: o# %la""
Ans: class ?class name @
<
ata member declaration;
Aember function declaration;
=
$,. 7o& to de#ine the member #un%tion in a %la""
Ans: ,he function that is enclosed in a class is called is called member function.
$-. What i" the di##eren%e bet&een #un%tion ' member #un%tion
Ans: 8unction is a bloc) of statements that perform some tas). #ut the function that is
enclosed in a class is called is called member function.
$0. What are the "tep" in %la"" program
Ans:
a) eclare a class.
b) eclare the data member . member function in side the class.
-
c) efine the member function inside or outside the class.
d) eclare the main program.
e) *reate the object inside the class.
f) Access the member function using the object.
(1. What i" the di##eren%e bet&een pri*ate8 publi% ' prote%ted
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.
(1. What do u mean by "tati% data member
Ans: !f we declare the data as static then its value will remain constant during the
program.
(!. What are the propertie" o# "tati% data member
Ans: Properties is given below:
a) !t can be shared by the entire object.
b) #y default its value is initialiBed to Bero.
c) !ts value will remain constant.
d) !t must be initialiBed outside the class.
e) !t uses the )eyword static.
($. What do u mean by "tati% member #un%tion
Ans:
a) !t can only access the static data member.
b) !t can be invo)ed using class name instead of object name.
((. What i" the u"e o# "tati% ob/e%t
Ans: %tatic object initialiBes all the data member to Bero.
(). What i" %on"tant member #un%tion
Ans: !t can not modify any data member in the class.
(+. 7o& to a%%e"" the pri*ate member #un%tion in a %la""
Ans: Chen we declare the member function as private" then it can be accessed in side
the public member function. Object can not invo)e the private member function.
(,. Why array o# ob/e%t i" u"ed
Ans: ,o display the output of more than one object we can use the array of object
concept.
(-. .i##eren%e bet&een lo%al %la"" ' global %la""
Ans: ifference between this is given below:
a) ,he class i.e. declared outside the main function is called global class.
#ut the class i.e. declared inside the main function is called local class.
b) +ocal class has only local object. #ut global class has both local .
global object.
c) +ocal class can not have static data member . member function. #ut
global class has static data . static member function.
(0. What do u mean by empty %la""
Ans: ,he class without any data member . member function is )nown as empty
class.
)1. What i" the u"e o# empty %la""
Ans: !t is generally used in e'ception handling program.
)1. What i" %on"t argument
Ans: Chen we declare the data as constant" its value remain constant.
D
Chapter: )
)!. What do u mean by #un%tion
Ans: it is a bloc) of statements that perform some tas)s
)$. What i" the need o# #un%tion
Ans: function is used for following purpose:
a) /sing function" large program can be divided into smaller ones. !t is
easy to debug . find out the errors in it.
b) !f we want to perform tas) repetitively" it is not necessary to rewrite the
particular bloc) of statements again . again. %hift the particular bloc)
of statement in a user defined function.
)(. What i" #un%tion prototype
Ans: it is a declaration statement in a program.
%ynta': return type function name (argument);
&': voids add (int" int);
)). What i" the #un%tion argument" u"ed in %++
Ans: ,here are 2 types of arguments are used in c((.
a) Actual argument: argument of calling function.
b) 8ormal argument: argument of called function.
)+. 7o& to pa"" the parameter" in #un%tion
Ans: it can be possible in - ways:
a) call by value( pass by value)
b) call by reference ( pass by reference)
c) call by address( pass by address)
),. What i" inline #un%tion
Ans: #y default all the functions defined inside the class is called inline. !f we want to
ma)e the function outside the class as inline" then inline )eyword is used.
)-. What i" the ad*antage o# inline #un%tion
Ans: &'ecution is very first.
)0. What i" the di"ad*antage o# inline #un%tion
Ans: !t ta)es more memory space.
+1. What are the rule" #or inline #un%tion
Ans: !t has following rules:
a) !nline function is used when the program contains few statements.
b) 4ecursion function can not be inline.
c) Aain ( ) function can not be wor) as inline.
d) !t should not contain static variable.
e) 8unction containing go to" for" switch can not be inline.
+1. What i" the di##eren%e bet&een inline ' ma%ro
Ans: ifference between inline . macro is given below:
a) !n inline function when the function is called the code of the function
is replaced with the function call. #ut in macro only the value is
replaced.
b) !n inline function" error is chec)ed during e'ecution. #ut in macro
error is not chec)ed.
+!. What i" the di##eren%e bet&een open "ubroutine ' %lo"e "ub routine
Ans: !nline function is called open sub routine but normal function is called close sub
routine. ifference is given below.
+$. What i" the di##eren%e bet&een inline #un%tion ' #un%tion
Ans: ifference between inline function . function is given below:
E
a) !n 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. #ut
in inline function when the function is called the code of the function is
replaced with the function call
b) Feneral function ta)es less memory space where inline function ta)es
more memory space.
c) !n function" e'ecution speed is less but in inline function e'ecution is
very first.
+(. What i" #un%tion o*erloading
Ans: functions having same name but different arguments are called function
overloading.
+). What i" the di##eren%e bet&een #un%tion o*erloading ' #un%tion o*erridden
Ans: functions having same name but different arguments are called function
overloading.
#ut 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.
++. What i" the u"e o# #riend #un%tion
Ans: ue to data hiding concept" non member functions can not access the private
data. %o to access this" c(( provides a new concept called friend function. !f we
declare the function as a friend of other class" then it can access the private data.
+,. What are rule" #or #riend #un%tion
Ans:
a) ,he friend )ey word is used.
b) !n function declaration" class name is given in place of argument.
c) !n function definition" object is created in place of function argument
d) !t can be accessed using the object name.
+-. What i" #riend %la""
Ans: !t is possible to declare the whole class as friend. !t is )nown as friend class.
+0. 7o& to %al%ulate the "i<e o# ob/e%t
Ans: %iBe of object is eGual to the sum of the siBe of all class data member of the
class.
,1. What are the library #un%tion"
Ans: in c((" mainly D library functions are used: ceil ceill" floor" and floorl.
,1. 7o& to round up ' round do&n the #loat number
Ans: float number can be round up using ceil . ceill library function. #ut float
number can be round down using floor . floorl library function.
Chapter: +
,!. What do u mean by %on"tru%tor
Ans: it is a special member function which is used to initialiBe the object of a class
when the object is created. !t is called constructor because it constructs the value of
the data member.
,$. What are the propertie" o# %on"tru%tor
Ans: properties of constructor are given below:
a) !t is used to initialiBe the object when the object is created.
b) !ts name is same as class name.
c) !t has no return type.
d) !t should be declared in public part.
e) !t can be overloaded.
7
f) !t can not be inherited.
g) !t can not be virtual.
,(. What are the type" o# %on"tru%tor
Ans: it is mainly of E types:
a) efault constructor.
b) ParameteriBed constructor.
c) *opy constructor.
d) efault argument constructor.
e) ynamic constructor.
,). What i" the u"e o# de#ault argument %on"tru%tor
Ans: ParameteriBed constructor having default value is called default argument
constructor.
,+. What i" dynami% %on"tru%tor
Ans: ,he constructor can also be used to allocate the memory while creating the
object. !t is called dynamic constructor. !t will enable the system to allocate the right
amount of memory.
,,. What i" the di##eren%e bet&een "hallo& %opy ' deep %opy
Ans:
,-. What i" de"tru%tor
Ans: estructor is used to destroy the object i.e. created by constructor.
,0. What are the propertie" o# de"tru%tor
Ans: a) its name is same as class name.
b) !t has no return type.
c) !t is same as class name only proceeding by a symbol tilde i.e. H.
d) !t can not be overloaded.
e) !t can be virtual.
f) !t never ta)es any argument.
g) !n a program only one destructor is present.
-1. What i" the di##eren%e bet&een %on"tru%tor ' de"tru%tor
Ans: ifference is given below:
a) *onstructor is used to construct the value of data member. #ut
destructor is used to destroy the value of data member i.e. created by
constructor.
b) *onstructor can be overloaded but destructors can not be overloaded.
c) *onstructor can not be virtual but destructor can be.
d) *onstructor can be called implicitly or e'plicitly.
-1. What i" %on"t ob/e%t
Ans: Ce can ma)e the object constant by the )eyword IconstJ. !t can only access the
constant member function.
-!. What i" anonymou" ob/e%t
Ans: it is possible to create the object without the name . such objects are called
anonymous object. !t is only possible in constructor.
-$. What i" the di##eren%e bet&een lo%al ' global ob/e%t
Ans: when the object is declared inside the main function it is called local object. #ut
the object i.e. defined outside the main function is called global object.
-(. 7o& to u"e the pri*ate %on"tru%tor
Ans: when the constructor is declared as private" it can be invo)ed through the public
member of the class.
K
Chapter: ,
-). What i" inheritan%e
Ans: !n inheritance a new class is created from the e'isting one. ,he e'isting class is
called parent5 super5 base class. ,he new class is called child5 sub5 derived class.
-+. What do u mean by reu"ability
Ans: erived class reuses the property of base class. !t is called reusability.
-,. What are the type" o# inheritan%e
Ans: there are E types of inheritance:
a) %ingle inheritance.
b) Aultiple inheritances.
c) Aultilevel inheritance.
d) Lierchical inheritance.
e) Lybrid inheritance.
--. What i" the di##eren%e bet&een multiple ' multile*el inheritan%e
Ans: !n multiple inheritances" a new class is derived from more than one base class.
#ut in multilevel inheritance" a new class is derived from a derived class i.e. derived
from another base class.
-0. What i" the u"e o# *irtual ba"e %la""
Ans: ,o overcome the ambiguity that is occurred in multipath inheritance c((
provides a new )eyword that is virtual. !f we declare the base class as virtual" then the
compiler ta)es necessary steps avoid the duplication of member variable.
01. What i" delegation
Ans: eclaring the object as a class data member in another class is )nown as
delegation.
01. What i" %ontainer"hip
Ans: Chen a class has an object of another class as its data member" the class is called
container class . the relationship between two classes is )nown as containership.
0!. What i" ab"tra%t %la""
Ans: Chen a class is not used for creating an object" it is called as abstract class. !t
only acts as a base class.
0$. What i" %ommon %on"tru%tor
Ans: Ce )now constructor can not be inherited. Chen a class is derived from another
class" it is possible to define constructor in derived class. ata member of both base .
derived class can be initialiBed using derived class constructor. ,hus the constructor of
derived class wor)s for its base class. %uch constructors are )nown as common
constructor.
0(. What i" the di##eren%e bet&een publi% ' pri*ate inheritan%e
Ans: when a class is derived publicly" all the public members of base class can be
accessed directly in the derived class.
#ut in private inheritance" the public member of base class can be accessed
using public function of derived class.
0). What i" the ad*antage o# inheritan%e
Ans:
a) !nheritance provides reuse of code. %o no need to write the code again
. again.
b) #y reusability" the development time of software is reduced.
0+. What i" the di"ad*antage o# inheritan%e
Ans: !n class hierarchy" various data elements remain unused. ,he memory allocated
to them is not utiliBed.
2
0,. What do u mean by #un%tion o*erloading in inheritan%e
Ans: !f function overloading occurs in inheritance" then using scope resolution
operator" base class member function can be accessed
Chapter: -
0-. What i" operator o*erloading
Ans: Operator is a symbol that performs on constant . variable. #ut it can not operate
on object. ,hatMs why c(( provides a new concept by which operators are providing
e'tra tas) i.e. operate on objects. !t is called operator overloading.
00. What i" the ad*antage o# operator o*erloading
Ans: using operator overloading" it can acts on the objects.
111. 7o& to o*erload the operator
Ans: &ither using member function or friend function.
111. 7o& many argument" are u"ed #or unary ' binary operator o*erloading
Ans:
Unary: using member function 3 arguments . using friend function 0 argument.
=inary: using member function 0arguments . using friend function 2 arguments.
11!. Whi%h operator" %an not be o*erloaded
Ans: scope resolution operator (::)" siBe of operator (siBe of ( ))" dot operator (.)"
pointer to member operator (. N)" ternary operator (O :)
11$. Whi%h operator" %an>t be o*erloaded u"ing #riend #un%tion
Ans: function call operator" subscript operator" assignment operator" class member
access operator
11(. What i" the return type o# operator #un%tion
Ans: *lass type
11). What are the type" o# %on*er"ion
Ans: ,here are - types of conversion:
#asic to class type conversion.
*lass to basic type conversion.
*lass to class type conversion.
11+. What i" the di##eren%e bet&een ba"i% to %la"" ' %la"" to ba"i% type
Con*er"ion
Ans: Chile converting from basic to class type" the conversion function should be
defined in terms of constructor. #ut while converting from class to basic type" the
conversion function should be defined in terms of operator function.
Chapter: 0
11,. What do u mean by polymorphi"m
Ans: poly means many . morphism means forms. %o polymorphism means one name
having different forms.
11-. What are the type" o# polymorphi"m
Ans: 2 types of polymorphism i.e. compile time . run time.
110. What the di##eren%e i" bet&een %ompile ' run time polymorphi"m
Ans: ifference between compile time . run time polymorphism is given below:
!n compile time polymorphism an appropriate member function is selected
during compile time. #ut in run time polymorphism an appropriate
member function is selected during run time.
*ompile time polymorphism includes function overloading . operator
overloading. 4un time polymorphism includes virtual function
*ompile time polymorphism is called early or static binding. #ut run time
polymorphism is called late or dynamic binding.
1
111. What do u mean by *irtual #un%tion
Ans: Chen the function in both base . derived class has same name" then the
function in base class is said to be virtual using virtual )eyword.
111. What i" the di##eren%e bet&een ba"e %la"" pointer ' deri*ed %la"" pointer
Ans: #ase class pointer points to both base . derived class object. #ut derived class
pointer points to only the object of derived class.
11!. What are the rule" #or *irtual #un%tion
Ans: 4ules are given below:
*onstructor can not be virtual but destructor can be virtual.
9irtual function can be invo)ed using object pointer.
9irtual function may be declared as friend for another class.
11$. What i" pure *irtual #un%tion
Ans: 9irtual function i.e. eGuated to Bero is called pure virtual function.
11(. What i" ab"tra%t %la""
Ans: A class that contains pure virtual function is called abstract class.
Chapter: 11
11). What i" generi% programming
Ans: ,he program that supports generic class . generic function is called generic
programming.
11+. What i" the di##eren%e bet&een generi% %la"" ' generi% #un%tion
Ans: A class that wor)s for all data types is )nown as class template. #ut a function
that wor)s for all data type is )nown as function template.
11,. What i" template
Ans: ,emplate supports generic programming.
11-. What i" the need o# template
Ans: advantage of template is given below:
Program siBe is decreased.
+ess number of local variables is declared.
,ime comple'ity is less.
110. What i" the di##eren%e bet&een #un%tion o*erloading ' template
Ans: ifference is given below:
!n function overloading more number of local variables are declared but
in template less number of local variables are declared.
!n function overloading program siBe is large but in template function
siBe will decrease.
1!1. What are the type" o# template
Ans: 2 types i.e. class template . function template.
1!1. Write the "ynta: o# %la"" template ' #un%tion template
Ans: 8unction template synta':
,emplate?class ,@
4eturn type function name (template type argument)
<
=
*lass template synta':
,emplate?class ,@
*lass class name
<
=;
03
1!!. What i" the di##eren%e bet&een %la"" template ' template %la""
Ans: A class that wor)s for all data type is )nown as class template. #ut when a class
is derived class template" it is )nown as template class.
1!$. What i" the di##eren%e bet&een #un%tion template ' template #un%tion
Ans: A function that wor)s for all data type is )nown as function template. #ut when
a function is derived from function template is )nown as template function.
1!(. What i" the di##eren%e bet&een template ' ma%ro
Ans: ifference is given below:
,emplate is used for all the data types. #ut macro is only used for
replacement of value.
!n template error is chec)ed during compilation. #ut in macro error is
not chec)ed.
Chapter: 11
1!). What do u mean by error in a program
Ans: &rror is a condition that does not allow a program to e'ecute or run.
1!+. What are the type" o# error a*ailable in %++
Ans: 2 types of errors are available: compile time . run time error.
1!,. What the di##eren%e i" bet&een %ompile time ' run time error
Ans: ifference is given below:
!n compile time error" error is chec)ed during compilation. #ut in run
time error" error is chec)ed during run time.
&'ample of *ompile time error is missing of semicolon" missing of
brac)ets" undeclared identifier. &'ample of run time error is division
by Bero . array out of range.
*ompile time error is also )nown as synta' error. #ut run time error is
)nown as logical error.
1!-. What i" e:%eption
Ans: &'ception is a run time error.
1!0. What are the type" o# e:%eption
Ans: &'ception is of two types: synchronous . asynchronous.
1$1. 7o& to handle the e:%eption in %++
Ans: *(( only handles the synchronous e'ception. ,o handle the e'ception"
e'ception handling mechanism is used. !t is built upon - )eywords i.e. try" throw .
catch. Try: e'ception is generated here.
Thro&: e'ception is thrown using throw statement.
Cat%h: thrown e'ception is caught using catch statement.
1$1. 7o& to handle the un%aught e:%eption
Ans: uncaught e'ception can be handled using following functions: terminate ( )" set
terminate ( ) . abort ( ) function.
Chapter: 1!
1$!. What do u mean by #ile
Ans: 8ile is a collection of related data stored in a particular area on the dis).
1$$. Why #ile i" not "tored in primary memory
Ans: Primary memory is volatile. %o file is not stored here.
1$(. 7o& to open a #ile
Ans: 8ile can be opened in 2 ways:
/sing constructor.
00
/sing member function open ( ).

1$). What %la""e" u"ed #or #ile operation
Ans: if stream: read operation
Of stream: write operation
8stream: both read . write operation.
1$+. What are the #ile opening mode"
Ans: ifferent file opening modes are given below:
Io"::in: used for read purpose.
Io"::out: used for write purpose.
Io":: app: add at the end.
Io":: ate : modify . add.
Io":: trun%: ma)es the file to Bero length.
Io":: binary: opens the file in binary mode.
Io":: no %reate : open fails if the file does not e'ist.
Io":: no repla%e : open fails if the file already e'ists.
1$,. What are the #ile pointer"
Ans: ,here are two file pointers: get . put pointer.
1$-. What are the #ile pointer handling #un%tion
Ans: see)p ( )" see)g ( )" tellp ( )" tellg ( )
1$0. What i" the di##eren%e bet&een binary ' te:t mode in a #ile
Ans: %uppose we want to enter the data int a:02-" then in binary mode it will ta)e 2
byte because int reGuires 2 byte. #ut in te't mode it will ta)e - byte " one for each
digit.
1(1. 7o& to #ind the end o# a #ile
Ans: ,o find the end of a file" eof ( ) function is used.
1(1. 7o& to %he%; the error in a #ile
Ans: ,he logical negation operator (P) is used to chec) the error in a file. !t can be
used with the object of file stream class.
1(!. What do u mean by %ommand line argument
Ans: Chen some argument is associated with command" these are called command
line argument. !t is used with function main ( ).
%ynta':
Aain (int argc" char argv Q R)
1($. 7o& to handle the error during #ile operation
Ans: using error handling functions . these are eof ( )" bad ( )" good ( )" fail ( ).
Chapter: 1$
1((. What do u mean by ST9
Ans: it is an advance application of template. !t contains several in built function .
operators that help the programmer to develop comple' program. ,he programmer
needs to include the header file to use the function or operator li)e library function.
1(). What i" the %ontainer o# ST9
Ans: !t includes mainly - components:
*ontainer
Algorithm
!terator.
1(+. ?i*e an e:ample that &ill "ho& all the ST9 %omponent"
02
Ans: computer: container
!cons on computer: algorithm
*ursor: !terator.
1(,. What i" %ontainer What are the type" o# %ontainer
Ans: container is an object that contains all the data or other objects.
!t is of - types.
@""o%iati*e %ontainer: it includes set" multi set" map . multi map.
SeAuen%e %ontainer: !t includes vector" deGue . list.
.eri*ed %ontainer: it includes stac)" Gueue . priority
1(-. What do u mean by algorithm ' iterator
Ans: Algotithms are the application that is used to carry out the operation on the
content. #ut iterators behave li)e pointers . used to access the element of container.
1(0. What i" the di##eren%e bet&een *e%tor ' array
Ans: Array is a collection of similar data types. !n array siBe is fi'ed. Ce canMt enter
more element than the siBe given. #ut vector is a dynamic array. Ce can add any no of
element. %uppose given dynamic int a Q02R. !f we want to enter 0D elements then it
can be possible. Automatically the siBe of array will be increased.
1)1. What do u mean by "mart pointer
Ans: !terators are called as smart pointer. ,hey are used by the algorithm to carry
operations.
1)1. What i" the u"e o# li"t
Ans: list allows the insertion . deletion of item anywhere. !t can be accessed
bidirectional. !t is defined in the header file ?list@.
0-

You might also like