KEMBAR78
Assignment No 2 Oop | PDF | Computer Programming | Computing
0% found this document useful (0 votes)
47 views5 pages

Assignment No 2 Oop

1. A valid pointer ensures that the correct instance variable is accessed correctly within class methods by helping with instance-specific data and methods. It stores the memory location of any data type you want to access. 2. References must always be associated with objects while pointers can be null. References cannot be reassigned but pointers can. Pointers can be used for manual memory management while references are not. 3. A friend class is granted access to the private and protected members of another class as if it were a member. It is declared using the 'friend' keyword and can access these members without access restrictions.

Uploaded by

officialanas589
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views5 pages

Assignment No 2 Oop

1. A valid pointer ensures that the correct instance variable is accessed correctly within class methods by helping with instance-specific data and methods. It stores the memory location of any data type you want to access. 2. References must always be associated with objects while pointers can be null. References cannot be reassigned but pointers can. Pointers can be used for manual memory management while references are not. 3. A friend class is granted access to the private and protected members of another class as if it were a member. It is declared using the 'friend' keyword and can access these members without access restrictions.

Uploaded by

officialanas589
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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