Sunteți pe pagina 1din 12

What is C++ C++ is created by Bjarne Stroustrup of AT&T Bell Labs as an extension of C, C+ + is an object-oriented co puter lan!ua!

e used in the de"elop ent of enterprise and co ercial applications# $icrosoft%s &isual C++ beca e the pre ier lan!ua!e of choice a on! de"elopers and pro!ra ers# 2. What are the basic concepts of object oriented pro!ra in!' (t is necessary to understand so e of the concepts used extensi"ely in object oriented pro!ra in!#These include )bjects Classes *ata abstraction and encapsulation (nheritance +oly orphis *yna ic Bindin! $essa!e passin!

3. *efine inheritance' The echanis of deri"in! a ne, class -deri"ed. fro an old class -base class. is called inheritance# (t allo,s the extension and reuse of existin! code ,ithout ha"in! to re,rite the code fro scratch# (nheritance is the process by ,hich objects of one class ac/uire properties of objects of another class# 4. *efine poly orphis ' +oly orphis eans one na e, ultiple for s# (t allo,s us to ha"e ore than one function ,ith the sa e na e in a pro!ra #(t allo,s us to ha"e o"erloadin! of operators so that an operation can exhibit different beha"iours in different instances# 5. What is encapsulation' The ,rappin! up of data and functions into a sin!le unit -called class. is 0no,n as encapsulation# 1ncapsulation containin! and hidin! infor ation about an object, such as internal data structures and code#

6. What is

essa!e passin!'

An object oriented pro!ra consists of a set of objects that co unicate ,ith each other# $essa!e passin! in"ol"es specifyin! the na e of the object, the na e of the function and the infor ation to be sent# 7. What are to0ens in C++' The s allest indi"idual units of a pro!ra follo,in! to0ens 2 3ey,ords is 0no,n as to0ens# c++ has the

,,,#Technicalsy posiu #co

(dentifiers Constants Strin!s )perators

8. What is the use of enu erated data type' An enu erated data type is another user defined type ,hich pro"ides a ,ay for attachin! na es to nu bers thereby increasin! co prehensibility of the code# The enu 0ey,ord auto atically enu erates a list of ,ords by assi!nin! the "alues 4,5,6, and so on# 9. What is the use of default constructor' A constructors that accepts no para eters is called the default constructor#(f no userdefined constructor exists for a class A and one is needed, the co piler i plicitly declares a default para eterless constructor A22A-.# This constructor is an inline public e ber of its class# The co piler ,ill i plicitly define A22A-. ,hen the co piler uses this constructor to create an object of type A# The constructor ,ill ha"e no constructor initiali7er and a null body# 10. *efine Constructors' A constructor is a e ber function ,ith the sa e na e as its class# The constructor is in"o0ed ,hene"er an object of its associated class is created#(t is called constructor because it constructs the "alues of data e bers of the class# o, "ariable declaration in c++ differs that in c' C re/uires all the "ariables to be declared at the be!innin! of a scope but in c++ ,e can declare "ariables any,here in the scope# This a0es the pro!ra er easier to understand because the "ariables are declared in the context of their use# 12. *efine destuctors' A destructor is called for a class object ,hen that object passes out of scope or is explicitly deleted#A destructors as the na e i plies is used to destroy the objects that ha"e been created by a constructors#Li0e a constructor , the destructor is a e ber function ,hose na e is the sa e as the class na e but is precided by a tilde# 13. What is a class' A class is a collection of objects# 14. ,hat is the difference bet,een c &c++' c++ ia an object oriented pro!ra in! but c is a procedure oriented pro!ra in!#c is super set of c++# c can8t suport inheritance,function o"erloadin!, ethod o"erloadin! ,,,#Technicalsy posiu #co

etc# but c++ can do this#(n c-pro!ra e the ain function could not return a "alue but in the c++ the ain function shuld return a "alue# 15. What is copy constructor' Copy constructor is a constructor function ,ith the sa e na e as the class and used to a0e deep copy of objects#

16. What is default constructor' A default constructor is a constructor that either has no para eters, or if it has para eters, all the para eters ha"e default "alues# 17. What is a scope resolution operator' The scope resolution operator per its a pro!ra to reference an identifier in the !lobal scope that has been hidden by another identifier ,ith the sa e na e in the local scope# 18. What is the difference bet,een )bject and (nstance' An instance of a user-defined type is called an object# We can instantiate fro one class# An object is an instance of a class# 19. What is the difference bet,een acro and iniine' ay or ay not (nline follo,s strict para eter type chec0in!, acros do not# $acros are al,ays expanded by preprocessor, ,hereas co piler replace the inline definitions# 20. 9o, "ariable declaration in c++ differs that in c' C re/uires all the "ariables to be declared at the be!innin! of a scope but in c++ ,e can declare "ariables any,here in the scope# This a0es the pro!ra er easier to understand because the "ariables are declared in the context of their use# 21. What is ultiple inheritance' ore than one class ,hich is 0no,n as ultiple any objects

A class can inherit properties fro inheritance#

22. ,hat is the use of "irtual destructor in c++' A destructor is auto atically called ,hen the object is destroyed# A "irtual destructor in C++ is used pri arily to pre"ent resource lea0s by perfor in! a clean-up of the object# 23. What do you ean by reference "ariable in c++' A reference "ariable pro"ides an alias to a pre"iously defined "ariable# *ata -type & reference-na e : "ariable na e ,,,#Technicalsy posiu #co

24. What do you


ean by i plicit con"ersion'

Whene"er data types are ixed in an expression then c++ perfor s the con"ersion auto atically# 9ere s aller type is con"erted to ,ider type# 1xa ple 2 in case of inte!er and float inte!er is con"erted into float type# The "irtual fuctions ust be e bers of so e class# They cannot be static e bers# They are accessed by usin! object pointers# A "irtual function can be a friend of another class#

25. What are "irtual functions'


26. What is the difference bet,een class and structure'


By default, the e bers ot structures are public ,hile that tor class is pri"ate# structures doesn%t pro"ide so ethin! li0e data hidin! ,hich is pro"ided by the classes# structures contains only data ,hile class bind both data and e ber functions#

27. What are stora!e /ualifiers in C++ ' Const3ey,ord indicates that e ory once initiali7ed, should not be altered by a pro!ra # Volatile 0ey,ord indicates that the "alue in the e ory location can be altered e"en thou!h nothin! in the pro!ra # Mutable 0ey,ord indicates that particular e ber of a structure or class can be altered e"en if a particular structure "ariable, class, or class e ber function is constant# 28. What is "irtual class and friend class' ;riend classes are used ,hen t,o or ore classes and "irtual base class aids in ultiple inheritance# &irtual class is used for run ti e poly orphis ,hen object is lin0ed to procedure call at run ti e# 29. ,hat is an abstract base class' An abstract class is a class that is desi!ned to be specifically used as a base class# An abstract class contains at least one pure "irtual function# 30. What is dyna ic bindin!' *yna ic bindin! -also 0no,n as late bindin!. eans that the code associated ,ith a !i"en procedure call is not 0no,n until the ti e of the call at run ti e#(t is associated ,ith poly orphis and inheritance# ,,,#Technicalsy posiu #co

1. ,hat is difference bet,een function o"erloadin! and operator o"erloadin!' A function is o"erloaded ,hen sa e na e is !i"en to different function# While o"erloadin! a function, the return type of the functions need to be the sa e# 32. What are the ad"anta!es of inheritance'

Code reusability Sa"es ti e in pro!ra de"elop ent#

33. What is a dyna ic constructor' The constructor can also be used to allocate e ory ,hile creatin! objects# Allocation of e ory to objects at the ti e of their construction is 0no,n as dyna ic construction of objects#The e ory is allocated ,ith the help of the ne, operator# 34. What is the difference bet,een an Array and a List' The ain difference bet,een an array and a list is ho, they internally store the data# ,hereas Array is collection of ho o!eneous ele ents# List is collection of hetero!eneous ele ents# 35. What is the use of <usin!% declaration' A usin! declaration a0es it possible to use a na e fro a na espace#

36. What is the difference bet,een a te plate class and class te plate' Template classA !eneric definition or a para eteri7ed class not instantiated until the client pro"ides the needed infor ation# (t%s jar!on for plain te plates# Class templateA class template specifies how individual classes can be constructed much like the way a class specifies how individual objects can be constructed. Its jargon for plain classes. 37. What is friend function' The function declaration should be preceded by the 0ey,ord friend#The function definitions does not use either the 0ey,ord or the scope operator 22# The functions that are declared ,ith the 0ey,ord friend as friend function#Thus, a friend function is an ordinary function or a e ber of another class# 38. What is a scope resolution operator' A scope resolution operator -22., can be used to define the outside the class# 39. What do you ean by pure "irtual functions' e ber functions of a class

A pure "irtual e ber function is a e ber function that the base class forces deri"ed classes to pro"ide# Any class containin! any pure "irtual function cannot be used to ,,,#Technicalsy posiu #co

create object of its o,n type# 40. What is a con"ersion constructor' A con"ertin! constructor is a sin!le-para eter constructor that is declared ,ithout the function specifier explicit# The co piler uses con"ertin! constructors to con"ert objects fro the type of the first para eter to the type of the con"ertin! constructor%s class#

41. What is a container class' What are the types of container classes' A container class is a class that is used to hold objects in e ory or external stora!e# A container class acts as a !eneric holder# A container class has a predefined beha"ior and a ,ell0no,n interface# A container class is a supportin! class ,hose purpose is to hide the topolo!y used for aintainin! the list of objects in e ory# When a container class contains a !roup of ixed objects, the container is called a hetero!eneous container= ,hen the container is holdin! a !roup of objects that are all the sa e, the container is called a ho o!eneous container# 42. What is Associati"e container' Associati"e containers are desi!ned to support direct access to ele ents usin! 0eys# They are not se/uential# There are four types of associati"es containers 2 Set $ultiset $ap $ulti ap

43. What is an iterator' (terators are li0e pointers# They are used to access the ele ents of containers thus pro"idin! a lin0 bet,een al!orith s and containers# (terators are defined for specific containers and used as ar!u ents to al!orith s# 44. What are the definin! traits of an object-oriented lan!ua!e'

The definin! traits of an object-oriented lan!au!e are 2 1ncapsulation (nheritance +oly orphis S alltal0 ?a"a 1iffel Sather

45. >a e so e pure object oriented lan!ua!es'


,,,#Technicalsy posiu #co

46. What is this pointer' (t is a pointer that points to the current object# This can be used to access the of the current object ,ith the help of the arro, operator# 47. What is encapsulation' 1ncapsulation -or infor ation hidin!. is the process of co binin! data and functions into a sin!le unit called class# 48. What is proble ,ith @unti e type identification' The run ti e type identification co es at a cost of perfor ance penalty# Co piler aintains the class# 49. What are the differences bet,een ne, and

e bers

alloc'

>e, initiali7es the allocated e ory by callin! the constructor# $e ory allocated ,ith ne, should be released ,ith delete# $alloc allocates uninitiali7ed e ory# The allocated e ory has to be released ,ith free#ne, auto atically calls the constructor ,hile alloc-dosen%t.

50. What is con"ersion operator' Aou can define a e ber function of a class, called a con"ersion function, that con"erts fro the type of its class to another specified type#

51. What is difference bet,een te plate and

acro'

A te plate can be used to create a fa ily of classes or function#A te plate describes a set of related classes or set of related functions in ,hich a list of para eters in the declaration describe ho, the e bers of the set "ary# (dentifiers that represent state ents or expressions are called acros# 52. What is reference' @eference is a na e that acts as an alias, or alternati"e na e, for a pre"iously defined "ariable or an object# 53. What are the access specifier in c++'

There are three types of access specifier in c++ # They are +ublic protected pri"ate

54. What is difference bet,een C++ and ?a"a' ,,,#Technicalsy posiu #co

C++ has pointers ?a"a does not# ?a"a is the platfor independent as it ,or0s on any type of operatin! syste s# ja"a has no pointers ,here c ++ has pointers# ?a"a has !arba!e collection C++ does not#

55. What is na espace' The C++ lan!ua!e pro"ides a sin!le !lobal na espace#>a espaces allo, to !roup entities li0e classes, objects and functions under a na e#

56. What is an explicit constructor' A con"ersion constructor declared ,ith the explicit 0ey,ord# The co piler does not use an explicit constructor to i ple ent an i plied con"ersion of types# (t%s purpose is reser"ed explicitly for construction#1xplicit constructors are si ply constructors that cannot ta0e part in an i plicit con"ersion# 57. What is the use of stora!e class specifiers' A stora!e class specifier is used to refine the declaration of a "ariable, a function, and para eters# The follo,in! are stora!e class specifiers 2 auto re!ister static extern

58. ,hat is assi!n ent operator in c++' *efault assi!n ent operator handles assi!nin! one object to another of the sa e class# $e ber to e ber copy -shallo, copy.# 59. Can destructor be pri"ate' Aes destructors can be pri"ate# But accordin! it is not ad"isable to ha"e destructors to be pri"ate# 60. What is strstrea ' strin!strea pro"ides an interface to anipulate strin!s as if they ,ere inputBoutput strea s# C strstrea D to define se"eral classes that support iostrea s operations on se/uences stored in an allocated array of char object#

61. What are the types of STL containers'


de/ue hash ap

,,,#Technicalsy posiu #co

hash ulti ap hashE ultiset hashset list ap ulti ap ultiset set "ector

# 62. What is the difference bet,een ethod o"erloadin! and ethod o"erridin!' Overloading a ethod -or function. in C++ is the ability for functions of the sa e na e to be defined as lon! as these ethods ha"e different si!natures -different set of para eters.# Met od overriding is the ability of the inherited class re,ritin! the "irtual ethod of the base class# 63. What do you ean by inline function' An inline function is a function that is expanded inline ,hen in"o0ed#ie# the co piler replaces the function call ,ith the correspondin! function code# An inline function is a function that is expanded in line ,hen it is in"o0ed# That is the co piler replaces the function call ,ith the correspondin! function code -si ilar to acro.# 64. What is a te plate' A te plate can be used to create a fa ily of classes or function#A te plate describes a set of related classes or set of related functions in ,hich a list of para eters in the declaration describe ho, the e bers of the set "ary# 65. What is a copy constructor and ,hen is it called' A copy constructor is a ethod that accepts an object of the sa e class and copies it e bers to the object on the left part of assi!ne ent#

66.

What is the difference bet,een a copy constructor and an o"erloaded assi!n ent operator' A copy constructor constructs a ne, object by usin! the content of the ar!u ent object# An o"erloaded assi!n ent operator assi!ns the contents of an existin! object to another existin! object of the sa e class#

67. What is a "irtual destructor' The si ple ans,er is that a "irtual destructor is one that is declared ,ith the "irtual attribute# 68. What do you ean by Stac0 un,indin!'

,,,#Technicalsy posiu #co

(t is a process durin! exception handlin! ,hen the destructor is called for all local objects bet,een the place ,here the exception ,as thro,n and ,here it is cau!ht# 69. What is STL' and ,hat are the co ponents of stl' A collection of !eneric classes and functions is called as Standard Te plate Library -STL.#The stl co ponents are containers Al!orith (terators

# 70. What is a odifier' A odifier, also called a odifyin! function is a e ber function that chan!es the "alue of at least one data e ber# (n other ,ords, an operation that odifies the state of an object# $odifiers are also 0no,n as utators#

71. What is an adaptor class or Wrapper class' A class that has no functionality of its o,n# (ts e ber functions hide the use of a third party soft,are co ponent or an object ,ith the non-co patible interface or a non-objectoriented i ple entation# 72. What is a >ull object' (t is an object of so e class ,hose purpose is to indicate that a real object of that class does not exist# )ne co on use for a null object is a return "alue fro a e ber function that is supposed to return an object ,ith so e specified properties but cannot find such an object# 73. What is class in"ariant' A class in"ariant is a condition that defines all "alid states for an object# (t is a lo!ical condition to ensure the correct ,or0in! of a class# Class in"ariants ust hold ,hen an object is created, and they ust be preser"ed under all operations of the class# (n particular all class in"ariants are both preconditions and post-conditions for all operations or e ber functions of the class# 74. What is the difference bet,een the essa!e and ethod' Message 2 bjects communicate by sending messages to each other.A message is sent to invoke a method. Met od 2 !rovides response to a message and it is an implementation of an operation.

75. 9o, can ,e access protected and pri"ate (n the case of

e bers of a class' outside

e bers protected and pri"ate, these could not be accessed fro

,,,#Technicalsy posiu #co

the sa e class at ,hich they are declared# This rule can be trans!ressed ,ith the use of the friend 0ey,ord in a class, so ,e can allo, an external function to !ain access to the protected and pri"ate e bers of a class# 76. What do you ean by late bindin!' Late bindin! refers to function calls that are not resol"ed until run ti e# &irtual functions are used to achie"e late bindin!# When access is "ia a base pointer or reference, the "irtual function actually called is deter ined by the type of object pointed to by the pointer# 77. What is "irtual function' A "irtual function is a e ber function that is declared ,ithin a base class and redefined by a deri"ed class #To create a "irtual function, the function declaration in the base class is preceded by the 0ey,ord "irtual# 78. What do you ean by early bindin!' 1arly bindin! refers to the e"ents that occur at co pile ti e# 1arly bindin! occurs ,hen all infor ation needed to call a function is 0no,n at co pile ti e# 1xa ples of early bindin! include nor al function calls, o"erloaded function calls, and o"erloaded operators# The ad"anta!e of early bindin! is efficiency#

! at is t e di""erence #et$een a %&'' pointer and a void pointer( )ns* A >FLL pointer is a pointer of any type ,hose "alue is 7ero# A "oid pointer is a pointer to an object of an un0no,n type, and is !uaranteed to ha"e enou!h bits to hold a pointer to any object# A "oid pointer is not !uaranteed to ha"e enou!h bits to point to a function -thou!h in !eneral practice it does.# . ! at is di""erence #et$een C++ and ,ava( )ns* C++ has pointers ?a"a does not# ?a"a is platfor independent C++ is not# ?a"a has !arba!e collection C++ does not# . ! at do -o. mean #- m.ltiple in eritance in C++ ( )ns* $ultiple inheritance is a feature in C++ by ,hich one class can be of different types# Say class teachin! Assistant is inherited fro t,o classes say teacher and Student# ! at do -o. mean #- virt.al met ods( )ns* "irtual ethods are used to use the poly orphis feature in C++# Say class A is inherited fro class B# (f ,e declare say function f-. as "irtual in class B and o"erride the sa e function in class A then at runti e appropriate ethod of the class ,ill be called dependin! upon the type of the object# ! at do -o. mean #- static met ods( )ns* By usin! the static ethod there is no need creatin! an object of that class to use ,,,#Technicalsy posiu #co

that ethod# We can directly call that ethod on that class# ;or exa ple, say class A has static function f-., then ,e can call f-. function as A#f-.# There is no need of creatin! an object of class A# /o$ man- $a-s are t ere to initiali0e an int $it a constant( )ns* T,o# There are t,o for ats for initiali7ers in C++ as sho,n in the exa ple that follo,s# The first for at uses the traditional C notation# The second for at uses constructor notation# int foo : 56G= int bar -56G.= ! at is a constr.ctor( )ns* Constructor is a special e ber function of a class, ,hich is in"o0ed auto atically ,hene"er an instance of the class is created# (t has the sa e na e as its class# ! at is destr.ctor( )ns* *estructor is a special e ber function of a class, ,hich is in"o0ed auto atically ,hene"er an object !oes out of the scope# (t has the sa e na e as its class ,ith a tilde character prefixed# ! at is an e1plicit constr.ctor( )ns* A con"ersion constructor declared ,ith the explicit 0ey,ord# The co piler does not use an explicit constructor to i ple ent an i plied con"ersion of types# (t%s purpose is reser"ed explicitly for construction# ! at is t e 2tandard Template 'i#rar-( )ns* A library of container te plates appro"ed by the A>S( co ittee for inclusion in the standard C++ specification# A pro!ra er ,ho then launches into a discussion of the !eneric pro!ra in! odel, iterators, allocators, al!orith s, and such, has a hi!her than a"era!e understandin! of the ne, technolo!y that STL brin!s to C++ pro!ra in!#

,,,#Technicalsy posiu #co

S-ar putea să vă placă și