Paper4WS
Paper4WS
ol. ) Jsg
&iteble
Hous
exam ple:
inline Runcton
s]
is betez han Macros oh
Ans - In object- osien ted Peogaromirg . inllne kunction aže
bette than macno Kunctiorn for thee olooig neoton
1. ee Salety
Macaos do not check dota types, ohich com legd to
CEEOES
Jnline tunchton eeloarn tye checking at Conpik 4ne
-
#
Ekarnple
+ includeiosteom>
define Squaze Cx) Cx)
ioline
sing
int sqLanse
narnes pcLQe stdy
Gntx)pctuen x*x ;] n atine du
2. funetonai y n casses
Macroos carnot be used inade closles effectivey
Jnline tuncton con be use d in closses t
sptimize
peeRoemane
EKarnpl e -
dass Mathf
Ablte !
Inline Int squaxe Gind ){ ||inline unelso
inside cass.
3. Re adabi Hy ond Mointaina bilHy
Macroos use
use tert eelacement, oaking debggng
hoede
fenctos Irgpzove reacbiHy nd Bloo
Jnline
G0P panalples
Relezences :
t.Baagurasamy Pg 80.
ciget.
Year. Ap Q093
[Roll no 22348]
|Paper 4]
3b. Wr1te a proqram tn Ctt.to awodb oanglng
ponter sttuation. (4m)
that
Danglng pointer : dn C langunge, ponde
dlallocated earlier in the pre qam is cal
iht Dargling ointer.
COmmon occwene
H Danglng p8nter is c
Ccs uhen ue lse the delete!
hat geneally duas pieviouily alocated
ihat
te dealecate memoy
ponte that was ponting do thad
and the Jhoe
kÐ dhe Jame aclads
also thor caes uhich lead to prter
are
eng dangeng poirder
" Deallscaton sf memey ung delete o
"Rehrencing ihe local vaiaie of the functon
alles is executed
Vauablt gees out of scope
Code
# tnclude iosteam>
sing nanmespace std
int main()
l lmemo rg allocahon
int*value- new intli)
D ireeing it
delete value )
cnt man ()
/getting the pointer lo the warialsle
Cout<< value: !
<*ptr<r end t;
/manvalls dealo
delete p~r ; caho g tb
)setioq pr to rule
p NLLL )
return 0;
3.
OUT POT ’ 9
Vaue. y2
Reference ’ Dangling poiltes n Ctt -qeks forfeeks
geeYs for geeks.o9g
22352
Roll 9o:22352 Apn
Year: 2023
K'apen-4)
4.c the
Explain concept o object cAeation and
destction in Ctt
coeathon.
class inteqen
poblic:
) go
class
ousde
A desbuctor
tne
hame dnd le
program Scope.
also has same name as the
ls patceded by a tilde
siqn.
-Properhes o Destoctor:
Salyys declated in poblic sechion
i) Does not have any arqumests
n) Does not haue a tetntype, not euen Void
iwy Destroys the objects in teierse erden of
Cheation once autside the
program scope
10) Syntax for Destrucor:
class Tnteger nClass definaton
poblo:
/Data Members
Memben torctionS
Destoucton body