0% found this document useful (0 votes)
3 views

C++ NOTES

The document discusses various concepts related to C and C++ programming languages, including features like encapsulation, inheritance, and polymorphism. It also covers differences between C and C++, memory management, constructors, destructors, and function overloading. Additionally, it touches on namespaces, templates, and the significance of object-oriented programming principles.

Uploaded by

Akshay Sinha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

C++ NOTES

The document discusses various concepts related to C and C++ programming languages, including features like encapsulation, inheritance, and polymorphism. It also covers differences between C and C++, memory management, constructors, destructors, and function overloading. Additionally, it touches on namespaces, templates, and the significance of object-oriented programming principles.

Uploaded by

Akshay Sinha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

1 Wht is ctt?

-
Ansc44 isian Dbjee drjented prDgrammlog landudde b-dh sn1C6
c 4 4 qives progrdmmer a hlqh le vel DE cbnhrol over syctem
b a dnd

Memory.
c44 is Jot OFwell- shdcured dnd sdfer ldndtdde 4hdn c.
slila obab h d bothid bob 9lbtroi nlla9se
c4+ is next
vers 0n dE C.
hotbil nb sbetobuA
7Wha die Advdntdde DF CH+ ligdat-
cHis an object orjeofed
pidrdmml nd langudde.
c+ PDdtdm Is dse Ful tor tew-1eve prodrdmming ldndudd e
eberbsilns zl 2922h/
3 Whad Is dIHerence bctube en c and c+
p1tno
dbpe9
tdsbes9-9btnbUbA

c++
els pdcedural ldnquade ob - c t ls prucedura tobject driened
PrDdrdmmind
datd is NDf secUred -
daBd 1s secdr ed
Mapping between datd and Mappind beltoeen dakd dn
tuncHDn Is Ntt
pbssIble.d 10dFuncHon s Possi ble. fyDUgh dbject
- We can nut use new dnd delele-We cdn dse ned dnd delete
oberator operadr t b
We not use uncHbn
cdn
he shucure.
inslde-We cdn use HoCHDD fOside
he shu chure
193r A
c ddes Not sUPPorHod TuoGHbn-cAf SUPPOHS
DVerldddin. FundbD
DverldddIng
4 Feaures In c4+?
to
Ans. up Df
datddnd Fuo cHDO
EhcapswaHor:-Wrappind

0ie3ui
d sindle uot s called ds EncapsuwaHDn.
Advandde - datd securieH.

4he dds DF represenHrg


bbat AbstrdcHDn- + refersl to
essea) Features dnd bidlod he bdckdrdund detau s L5
-

Aclvdotade- dad Hidind.


c Inherltdxe ;-Inber1tdnce 1s he prcess DF dduarind
the properi es oh one cldss into anDther cldss
N e d classes are called deirived eldss dnd esNsHnd
cldsses s called Bdse eldss

Adddntdde:-Resudbi lity dod Exfensibi1it.


d>
pDIy mbr phlsm:- A siodle enHfy cdo eAlst.1n. mbrev
tubebo 1
obroi fhdn one torm.
aten61hg

Adudn+dde-Hexibi|\h
5 deHne ndmespdce in C++

AmsThe ndmas pdce is bglea dUisIDn DF +he cDde bhlch Is


bdes1dned to SBop ndmfod conli ct
the main, use o ndme spdce o C44S o TemDve Amb1gu
-

Usind ndmespdce, De Cdn create foD vdHable houind


Sdme ndme.

d e Hne foken fo c44


Ans-TDken Is d teuDdrd 10 d c++. Ard l s asd ldenHHer,
4eral conctdt and symbol.
deHne std d ddd131 t1)-Pm13
g5f
msStd s, he defduf namespde staoddrd.6 /urt rl510
d75 h5lh adhn b 1 t d
ful foim oE STL ?
8 Wha s
Ans S TL sdndard templ ate librdry.

d) How delelet) is direrent om del efe


ms delete ls dsed to reledse d unit oF memory dnd lhd
deledet s used to reledse do Aray 1adgltoe
blo
u19h n9dl
bloshd orabe rodol 22bfs
Nhd 1s deshructtr ? btI19dat olqlurrt bob70b
hns- destuepr 15 d special member kuncHbn ot d cldss
ohich 1s
Inodked duomacallyo deshroy he bbjeet when he spe
S CDmp) efed. sth ( otyado adlwloe91 51932e
sldsro
b 9/dbibu Ibdf hob Ind gls 09d
(obr 9cahe s
11 What ls Consthucor ? 9dt snl19b at bo2 al
,tlhobi1o-fen971

Ans-A Consfu elor 1s


stecal member funcHbn df d cldss ahfch 1Se
d
InuD ced
duomaHcally Dhen ao objee dE the, sdme sldSS Ms -2(A
created the cbjec get auhomaljcal fníHal2ed
Iy by, cdnsbucbr.
edct.b2b bre19
9Pe OF CDNSHu dhi:in bt)ly
ay defuH CDOsbucor:- A
Consucor whlch dpes ntf decep
Pdrdmeer is called ds de rdut consbyctr. dOy-2n
pardmeized CDnshy cor- A Conshucor, tolthi One dr mbre
drdumet s called
r bavhh9 apardme2ed conshtctDrr abe

cCopy CDnstrucor- A Dpy ConstrU Cor ís a 22bl


speca cose DF
Dnshctors used to make copy DE Dne a

4 b
tbjec dnd iniHalj2e
dsing andtbêr objec dF he sdme cldss
hype.oe
-

shallbu) topy:-Dpy one dF he


objec to anbther object to
he belp DF CDmpiler
pioulded cDpy Conshu ctbr or ass idhnmert
9

Dverlbaded operabr Fundibn is called shaljuD


CDpy.
deep bpY:- CDpy Dne DE he bbje to the anbther object w(th the
help DF User
provl ded copy conshy cor or
eserecor bverlodded
Dperacor FuncHDn 1s called deep CDpy.
12 Explain his pbinte e
Ans- hbis pDinter bolds +he dddress DF OyIrent objech
13 Wba 1s Virtud inber itance?
Ans- VATHua) inber itance is dsed o remove 4he dm blguiy OF bdse cldss.

When derfved cldss Inher Hs sdme bdse


class v ld other cldsses
durfnd mulHple inherittNC
bso Hreoob boddu
14) Whad does saDpe restluHon operador do
99d2
1
Ans SCpe 1esolufbn operater (::) dre ysed to deeess afbhal vaHable
Dhen afdba dnd tdea vaHdble dre the sdme ndme.

4 Ls used to de Hne he member Funcon duHse the cld ssena) A


2
ootbi 9 r
b9dunt
15) Wba 1s pure vityal funcdjDno b 9ic I l n o l l n a v a l r b
1.,botn219
Ans:- A vitua) FuncHdn4ha Is decleared but not de Hne ín d
bdse cdss is Teferyed td ds d Pure virfy ad tuocHon
6 Wha is Nirtual deshuctor aan slls 193mbvbet
Ans:- VirtUal destrucor Ss d destudor LDhlch 1s deHned in bdse
cldss A - 1 3 o bedang
9Shf9Mh

slyctenal foooubib
14 s dseddet proper desuchor calls hom derived tb
to
bdse eldss when he bdse cldss poínfer holds
derived
cldss dunamic cbi ect. s Utene

17 Wha Isope rabr dverfbddInd e i oidd f


As operadbr bverjodding in c44 is dn Dverlocded declaration lnrle
s d dec (araHDn fnsame scDpe tuocHDor ofercor
of
decjedred toh he sdme ndme mDre hao bnce.1 o b b a l e u d
bsllno ai
g d gdlhnria
s)Whdt is tupe cdsHnd in c4t?
fns:- upe edsing Is dsed to chande the ddta tupes atgo29 n

4 hds Hod types


a) Implic4 14 1s dutomaic
byExplici4 I s user
deHned
1y wWhat is sheam in ci4?ot p/nflhd t fo
nsstream ye Fers to a shedm of chardcers to be frdnsfer red
beld eeo prdgrdm hredd dnd ilD.
20) nWhdB Is conio.h in c4+?
Ams-conib.b js g
indo sblos 6a3 nzr9vinu L r
hedder Hle dsed for console 0Pud dnd budpu i
OPeabns: b s l pd s- Bd sg) 1sliqeas ndio sho9d9b
And 14 1s dsed to
cieaHoq tert bdsed user jnterfdces.
1or2nt
2) Whdt Is (DStredm in C+4 10 9
Ans:- 0stre do s he hedder Hle
ohjch conains all
OF
prDd do libe Coud ein 'te.rmug he Fun cHon l

9 Wha} ls Hush
in c+t botbbglinvd adllbnb blinitN
Ans:Hush is sed do Sunchrdn}ze the dsst
wh is claded stredm bUffer
cDhd|led ourut O nu
sequence
3) Wb C+ cdJjed as ObJect
br|enfed progrdmmind Piaibotui
Ans Becduse cH ntd 2
dndudae vleD a prDblem in frms iOf objed
1DuDfved Tather hdo he
pocedura for doind i4.
OOP Is do
prbdrcmmlnd parddidm bdsed on he
datd in he toim cbncepnlgar
DF objecc which may coains
DEHen JcNDN as
DF Held
aHrbdes dnd cDd e lo he orm
OF
pDcedure dHen nDn as
mehtd
24)Wha 1s FundHDo Bindind
Ans: Resolbing a uncHon call c/4h s proper FuncHon, deinsuibo
hobd5
s called ds tun clH dn bínding 29qpt dau hr

25) Wha fs boot


Ans bDol s a daBd 4upe boohs9 s1lq
bool 7epresents O and only CFalse and f ) nre hlr

26) Ilhad 1s wc har-t ? al bot 5rtnbthaid n99 03f9d


ns- ochdr-t Is d dodd upe.
1 4 is unjversal CDde l
19-10bab big
wlde chard cdersIha 1ekbabld
9l0na3 alaos-200
slze 1s depends aupbn D mpiler (32 bit =2 by e, &64-bH 4byk)
2) Wha is 1eference vaHable ?
Ans + 1s Used o provide alids
ndme or duplicate name or
anDher name for
esdsina naHdble.i bb3 h
O
syntox dardhype & neDndme eAsHnd ndme
=

26 Whe Is funcd}bn bverlbddi nd


Ams:- de Hnind
mullHple funcHbn ith he sdme dalu 2/t
bl2 42 ndmé is called
FundHbn tverl bdd 10.
a r 0 bollddnao z t a s
9909 ba
24 Inline tuncdn?
AS Inline tuncHDD 1s d FuncdHDn ohere
funHon calI 1S
Teplace to uncHon deAniHdo.
9 ob 19dfI baulguOt
balab n 6 oa
3 Whad 1s class
patmobibgikl ab 2/ g00
6e bef abibti0t
tns- tldss s d CDIlecHon 6f dadpl member dnd member tuncHD).
3) What is trmend tdndibn 2
AnS: fiend Fu0dHbn 1s NDN- member FuncHon tohere cdos n
Atcess pHHvale dnd pofeced. daBd OF mém ber Df cldssnll
32 I hat s iend clds5 ?
ms- hiend c ldss is d cldss Onere bne
cldss all the member
fuocHon can dctess
pH Vahe daa Df dhbther class
class
33) What s siaHc datd
tMember
Ans:-14 Isbe d tloba vdHable or s
o a) he oblec class. i+j+ is dualla
dvalla ble
OF he
cldss.
defdutvalue DF saHe dadg member Js 0.
34) lha Is
sihdetbn cldss:
Ans- A class coman Dn)y Dne
dbj ec Is called
4 1s
sindleton cldss. born
Used
-

In NL medua player and


windtuo Adc mdndder
35) Nhad Is smdrt pdInei?
ms Dbject wtr Ung 11Ee d
poinfer
objed holdinq poimer o
dungmlcally allbcate memony
Usea VD1d ddrsade
b
iniHal2aHDn
VDld membry 1eak
c reduce he dDde cbmpljcity.
34) nhad s Erceptlbn Haod lind
Ans- EKep-Hdns Dhich octtis ad run-Hme dde to
To hdndie such Unusa tondi in.
efpiessID e epHbD hdndling is ued
-
A r bock oj1l hrow an
ACepHdn wln bnw lceuuDord.
cahch blbck toíl) handle he ecept}bo
seny hvoo. tondilHbn Dhich 1s
37) Whaf s fempl ate
Ans-emplades gre he teakyies bF the piodrg mmírg ldndudd e hodt
aloDs Huo tHDndnd elasses o operade ofth denericHApe
HundHbn Dreldddind dnd thon DverHdind'-
) FUnHdn Dvêrlbd ding: 1n
tundHpn Dverlbdding, DD Dr mDre FundHon tdn
OOn he
Sdme ndme lolhe
tndHbn ndme is overlod
pdrdmeler tpí) oe derenH, Dhen d
ded DÍh mal Hple dss
fundHon tve lodding. ldnmen, 1.e. couled A
NO Uncepl tt Inheifente tmdte
OpeHme polymprbhism nst irl lsla19fb
habpen in tompile Mmne.
HindHbn bvertldiod- funcHDn Dvêtd ng -2
pDDl dw an duhbhy to
d mehboe
rh he sdme ncme drd he redb10e,
claus. 9hbobO7
s1cnafure a he
fnherfne
need inheMdnte ontept
Un Hme pthWmDrS)
19oto b 71 prlfrog b9do -at
happens in Un me
d9iato palblad hajdo
l s rinolrepolh
Nome Mona ling- FundHbn DroHodd tollbLDS name
manglind Conc ep
Ndme mong fing Is he piDceas by C4
CDmpllers, phe
chonde3 home4o ereru fundDD by dddind dddiyonal
AOhormoHDn oed dr fun dDn n cme cnd
grq um ens

ndllg99h9nn ia balel pet A


palas
. butesal r
* difference belween ReFerence dnd poinHer ?

Rererence poiter.
Reference vdrjdble must be insalized. |pofnfer mdy or mdy nbt be
iniodioed.
2 NU reFerence ts
NDtPOSstble,i a NUtL Pofnfer fs possi ble.

3ReFerence vdriable cdo not polny to 3) poiner can pofot fo dny vdrldble
dnDfher vdrfable a dny Hme.

4) Reference vdnable Dil] nd de 4 poers des 9eperade memory


seper aBe memory. aos hdt
5) Reference toill det de-rererence pbinfer oill de de- reference
Implicty. explieity.
oboeredleo(
6ReFer ence to ReFerence Not pDss|ble.
6 Polnter o pblnter poss1ble s o

Prd Of Teference ls Not POSsible. 77 Ard OE PDIter is PDSS Iblea6

dtFerence betueen Mdoro dnd inline funcion

MOcrd Tnflne funcHon.


Mdero Ís one instru cHon, H Loil expdnd A Hlncbn call repldce ojth the
the code oith muple fnstue HDo.

H s Mdnd abr o repldce. 2 Hs requesfind compiler iF Possi ble


Df rtpldte 14

MdcrDs dre expdnded by pre prbeeasdr3) Inline fUncHbn dre pdssed oy


ranslador.

4) Macrd cdn hdve N ntmber of 4 fnline FUncHbn cqn hdve fess


instrucH dn. (nsHrUcHDn CNol mbre ha0 fDD
or hree fines)

S)se keydord ttde Hne 5 dse keuoold ioline.


dIference beltdeen NeuD opercudor gno Mal loc
NeuD operador Malloe
dperatdr dnd H dDesnt y Mallbc Is d (lbrdy funcDD dnd Hs
New is dn

Irbrdy. HundHbn. reduired ffbrdny funcHD

a) s2eDf operador ddesnt reduired P s2e of opercor is redulred.

s) upon success it return etdct poiner 3y Upbn suaecs 4 reuns vDld pojyer.
Hpe

4) pecdslind dbest reduired 4 HupecdsHnd Is redujred

6) Upon Fallure hrb dn etcepljon SdPon retuns 2erd.


C do Hme errdr)
. GmaloC)
6) main CO

P new 1nt C4b); P= CI +) mal 'bc (s|2eof(Int + )* 1o) ;

7 MemDry Tni44ali2alibn Is PDSsÍ ble. T Membry infHaj2afdn ís not Poss] ble.

dlErerence betbeen Free dnd delele ?.


ree delele

Free Is Ifbrdy FuocHdn 17 delee Is do bperabr i


a Dverlbddind is PDssjble
2 Dverlbdding noj POSs ble

r e e runcHbn doesnt call destuthor 3 delele operatbr dbes call


CLptn objeef deshoy deshuctbr upbn objec des þoy

difer ênce beween c sfture dnd C+ stcdre ?


c sudture c4t shudure
1yc stucure contains onIy datd members. c t stucture contolins date) member
and member FuocHon
for ex- she s+
For ex shye st

UDId 4est C)

2) CempH shrycture sl2e ls 2erb b e 2) C++ empky shyecure sfae 1s 4 bye

2 Ih c Access speclHer not avallable i n c4+ Access speciHeis dve

to prolec daa. avallable fo profect dada


dIference belueen c4+ shuure cnd c4+ class ?
c4 s cure c+ cldss
B defdult membet dre pu|lc. ) By defqut members dre plivade

a) By b i h þroperes o sdure
2By blrh properHes bf cldss
dre public. dre private.

3 By defdult mode ot nberitolnce 3 0y defddH, mode Df Inheritdnce


15 pUbl1c. s pruahe.

dlfer ence betuween Constydor dnd Member FuncHDn ?


Consuctor Member FuncHbDD
Constdcor ndme sdme ds eldss ndme. Y Member funcHbn cdn hdve dny ndme
2 CDnshdeor does nDt hdve retm fUpe. 2 Member tuocHbn hdve reum ype.

3 1+s used tor IniHalj2aHDn PUrPose. 34Is Used For dctessing or mbodT Fy
he dttd

4 CDnshcor cpnshucHnd dn objec Member funcHdn dbes nbt credfe object


6) Constdor caul dnIy one Hme fo do S member Fyodion con cal] N number
object OF Hmes

6) ConstUcor ca not be rMend rmember FuncHDn cdn be rlend of


dnother cldss.

CDnshucor cdn not be uirtual Member uocHon can be virtu.


* difference beueen shallod cop dnd deep cDP?
shal tuD CDpY deep cDPY
y shalbuD CDpy stDres he rerer ermes of y deep cDPy makes d ned dnd seperctte
objed tD4he bridina) membr) dddress CDpy of dn entre object col4h ts
Unique membry dddress
2 shallbD CopY is fasBer hdn deep Cbpy. |} deep copy Is slouwer than shalfow bpy

Shallbw Copy reHeds chandes made to 9 deep Copy ddesn4 reMe ds chdndes
he neo copf ed obj ec In he mdde to h e neo CDpied Dhbject o
orldina dbject he ondina) objet
diference betoeen Member Fuocibn dro friend Fuoclion ?
Member HuncHDn Friend fun cHon
>Member ncibn belbnds to same Friend Huncibn not belonds D
cldss Sdme cldss

2) Member runcion oill hde nfs ) Frend FuncHon dees not hae
4his pojoHer.
Polnter
3) member FuncHbn toil Inubke throuah 3 mend FundHon oi invoke
he dbject CDILhbud dbject

4) Member FuncHbn con Access a mend uncHDn can Access


mdmber DF ctdss oithoud object member Df class toIth objecd

5) The SUDpe of member FundHdn s) The scope DF fend FuncH on


belbnds to same cdss belbnds to inuber DF cldss.

* dference beBween conshuetor dnd desbudor e a to b d tun

Conshyor
despu
ctor
CDnshru cor uonstrycHnd he objet y destycor desboying the object
suokaa AC) Suntda AO
INe cdn pdss drdum en to he | We cdn not Pass drdum erd
Conshu cor tD he desty cor.

3 Conshdor overloddind 1s passIble 3desbycor bverloddind is not possible


4 Uirtua) is nDt POSslble 4 Uirtual destetor is Possible.
5)Conshy ctor is d speca) member fundlH bn s) deshucor ls d s pedal member
Of d cldss phichIs Inuked dltbmaHcalyFuncHon of d class ohich is Invoked
tDhen an tbjed bF he same elass Is duHomaHcally fo deshoy he bbj ed
creaed the objed de dutbmaHcall1
Dh en he swpe Of he obj ecd Is
toisalf2ed by he wnsh cbr Compleed

You might also like