You are on page 1of 5

Name ' Mehamnad Anas

AsSIGNMENT-I1

Whd is tie thi's poinder. Exphain


with
The tis' ponder in (+t Yfers
- Thu
ussend imstcnce of a clas
difeseniada betweem imstnca vavablos and Lscal va iab
toith tw
tie Sane name. helpg im accassing instanie-pecfic
dcda and methods. Heors a bief exan ple.
# nudi < iostean
class y duss
Pivate
jnd val';
Publici
My class Cid e)
tus-vlu

void poidvalec) {

ind mam()
my class objs (a2);

velurn 03
this CKam p thets Poier ensres thtthe Cortet
InstOne vai abl is acese d colHkn closs mthods
n l pointers with exan plo.
Anse l 1. Veid peivdeo ('veid))
)A vBld poiter dses have a Spefic data tee.
It
type memery toccdions amy data
you d to cast it Ao the gpropsiade ty ee befove
duejeeniy.
void

Pt

A ul pointe dsesn' t psit te yalid me meoy


> Desegesning it ty picly esut in a stim
int pA NULL',

use vaid roivdess for generic poindes manipuuian,


nd to
involid pojmders.
uji niliaiged
Auus s hat is dfferene btseen psinter end
Tefraes.

docdase and devefenenc.


* Refeoences use & eed
decavatien but don't netd
erplict
2.Nulabtity'
Poindeos be nul.
Peferenes must aloays de assoiated with vals
sbiects.
3. Reassignent
Can beTiaSS 197ed to diffesent cbjecis.
bnd to tone cobject dusing
initiai goien and Cannet bu 3eb lund.
Memosy Management
Peinders (am be used foY manua memey
management.
in veve memesy management.
S. funtin gas aineteIS
Panders and efeenls con be uged to
PASS Defeene to funcims.
demonstr ate pontu
to bae ad derived dasses.
# incude <
iectean
class
Publi'e:
it baSe Vas!
Base (ind x) : basevan (x) {}

Std : : Cuunt

lass Diived : pub ie Gese f


Pubie
int devivedVas ;
Dzived(int ns nty). tase(*), dived Var ( )$1
S d::Cbud << Disived;'e baserar
3:
imd main () g
Deaived ani vedObj (20, 9o)
Base* base Pty=& basobt
basert-> dis play O3
ba_eP iiedobj
Desi vod * disivede4 = &dorivedo bj ;
dsived P4 >dsplayco

Explain frlend cdass oith eKampl.


Buas 5l-
A Iviend cass id a lass that is gxdned
acCesS ond poe tected members
to the paivode ond
ane the cluss
Can aCcesg thse memblo s as if they
9sn.

> frind clase ave declased usig the'find' ay ood


hey ave used when Jau hred Conded access
to anethes cluss's indesnals .
E
pivate .
ind secoe Valu;
friend clsss FaiendClass
ublie:
Mysecset Clas (int talue) sexetvelu(value) ?

Qub c'.

ind Volu =obj. sevetvalue


3

You might also like