0% found this document useful (0 votes)
34 views28 pages

Pointers Notes - 231208 - 151350

Uploaded by

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

Pointers Notes - 231208 - 151350

Uploaded by

sandeepsai2508
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 28
© scanned with OKEN Scanner © scanned with OKEN Scanner | Acesteng a yowane dnovgh Le Pa key: © SS eSATA SD ae ; once a peinter fas been amugned the | actives, “eM! at OF a variable ; then how acces’ UC Vali a ! lace | Q Variable useng: thes sporntey me } fs one by ueing unary operator accent, ($b 65 Enon, erate . as indivection cov) dewerevenrcing, operator fxd int jasto, nsiideteette ne > 'e AO Cony, tne Py ight UP ES tov 2 2a 3 [ienivenresotton faa tT a iidcidting ve Brite « ns 4B5 aindevection [dereferena aaah URGE are ns ¥ (20) sperator., is hs O& 6 ainda be write ci Preqram. \fppncees the. values “adresses. of Vata ble, 14eing ,PeINEEYS. oo) Henctude ¢ tedicarhiag\) ret oie caprateg dy any vwserags int Q=t5,n ,¥P; P= ka; . opb dat 2¥D; PRP ES tit Pi PA nit Vole oF Oy = A ol oe 4060 « Prine iG aan! oo : Goeo~ Print # (“vame of p Ise Point? ("vame of, (Se Printe (* A995 f (vawe of ¢p -h d\n”, xe); 1S Print? ("vate of diab 4oroe Print (" ‘d\n’, ¥(ba)) 3 Value 66 &P 2% yin? 1 &P) 5 4) auth \ © scanned with OKEN Scanner yt vee ; dood > address Pe aS ne bs co one iy APF adares of e Wiad Mf ye. aber artthmene ; pane warcabtts ave dsb eridaan Beer’, becouse they aye | Weed)! address Of @ Vawtable. yy! here ave only a few opevatlons owed t0 Perform pointers ener \ Ws dddvess to stove that ave Increment foecve ment: on a pointer Adattion of a tneeger to a ‘potnter Vaviable. » Subtyaction of Oi Gee" Pret Qa potnter varta ble. Subtyacting 2 potrter’s of! same datatype. BO Ae 9 dasha Beni 9 rahe ‘Vrdoiry Bacrenment eto i ‘when a pointer ts “tneve mented it Hihevernenies by! the" nuiibey “ead to the \gtzex of the data typeritoy which! it (s , Sots hog A COS ‘when’ a potnter es decremented ¢t decrements by the num ber -edutat to the ze of data type fov wach” tw as | paints py SH cap hoop J : filesive es be i. Siu fh) Liverter tes Fall aa Saale \ #4 YO cppitodt!obivaey Swot Momo ip ately og nee ony 3 © scanned with OKEN Scanner jp pointer odlaelage Bo ogyd oo Inevement ongétremens i Leann » a3 2 Redes ev pointer Ee? euppore p, “s ie gs jy Oe 4 it hotds addwes |iovo. 4 P, Prt dota.type!))/!" Wie ods bi em care of ent) 5 bulk ef Gat of tne) eal tact eed SOKO 4 ad! irony Ried mY) 71936 = (ou4 ie) odd, 2 ctolt Resram. + yo woh yy ob aap | brsAy 4 PH maida pie) 9g hotel Hindudecsedioh> iti maine ) 5 ‘ "oo 0} oy YO ol eba +B sHor 19. Hwioorddy int wd OOTY ai 92 Pur 8a. fy igh ean ay dye : 8 youn want Mew cee tocye ment P, = UN", Py Jsmayseone | P. tt; . Sy We haseet sel? 2) FSS eg C“agegy, igypenen Pre n’ Ay PIs F108 Print C" before, deowement es 2O\N”, P)): : Pej town print Carter decrement PETRDAD", p,); eestid | a § ats ate j Py stat ON pd singers e9 Wu oxy St divecliy acess the Howory So paste pole dis adv ( ae i 7 ee \ : 14 a oniabalrcotien 04 patito might Chur “2g une My Incorteck Values ayes ubele pot ates, ote hi rua % a © scanned with OKEN Scanner en oF k ‘ Pointer és added aK a. vause » the Value {S Muttipued by the ee ot And then added to a pointer: + Subtraction ‘sy siipe dyes Bees oy Ca oe tegey from o pointer variate + Yr Tia algine gr ea bo sya ab when % Powter ic cubriacted with O niGS,, matt plied bY, the eri kt datasyre and then “cube acted Addin } woken se Suppo Pp, ts ofngeger, potn tev ia ee, 5 PERL ta, Pre Pro® I A = By 3 catze of nt) Py u P, - acstze of no) i eeaaea), ‘ = pat) i stouo tie “ = tuo 8 | +1082 iy 032) «| | : AONE A OS S Wyas1gidbtt \ Ex pinende estdl0.h> 45 matnc > L ORL eh Ge pen i int eS RP HPS, = adh RAS, Poe MBS Der th Oe) SR Hie | print (" bepbrd ‘adding p= 2 P; me. Pur Pyetdis Bho) bo iie = AONN", ° erie aN ge | a Scanned with OKEN Scanner pad _ | 4s Subtvaction i) Saree + “89 pa by aap , ON", 0, Print ( cebew eubtrosti gy Bag - 8) ae ag ibosge eee a? y j 4 Y ‘ib ey ae jy | gpa akpt 4 of 2 PELALEES 1 ; f OWE ay Le only wher oe = GE ts posed datatype, . E whe “ecu es) generated bY am ttference Mod aay nary Hegde gf le | Pate vc between! |B addire ses Of & Gare ung pout any bits OF data. x dt bs according to pointe? | data. ‘type fay futibb Oy. (EBL ipbore 6, @ pp are infteger Pointers sib ny ded che Sapa MPe ed (rs ! todo” “p, maine yi b-0ib 2. bawynte ‘ { © jatar tnt a=6,%P, ,*P, je; EV Dy aH Qe i) I Po Rahs ° fl Pointe addres ag pil yuin”, °1)5 (9 Qe ®: 6.35.44 soon Paint? Cadaven Veg pyle HOO", Pr; Py SPY J \inieg OIG Laie © scanned with OKEN Scanner P « __——— tC Value op as Pod NOV [ors ral VbN Bo fed On Operators avarlable ¥P, F4PD Ys EP) ERY fam = sum + ¥p i Pp > HPL HDG stk include maine > { fi int ¥P, xP); int @= (0, b=184 65 x5 dowe'h ine Zs 5" cep lexre.y+yi REY Si ye fame addres or Net. : 2427 to compitye itwa pointers when ths potte “the elements OF Mie ys gordi | : Sane array point to | ene | 4 ‘using bstnbeys 0 peetghirs all ee ae © scanned with OKEN Scanner CO EE LF Whoo ib Vo) Vee ee ~ d tee Prk bil ge bord tH oP il YE #0) -- 5 #P, 5 Fe) FPL eae 4 c= > Cpoft te set Pad 5 val ifs dob ay Poens ARe telO gi (i, Forte Py Bata lg Py 5 2 25825 2 bas n before he you Paint” C Walitte Ob” tP, - dro des; 1 "Prine C8 “Vauiie” “or *PL= AAAN", 18); Prine C ab ter. vane ‘of ¥P) = din”, 101); pints C vawe of ¢ = Sid AN)", €)5! Punt t (“ agver waue of way | yain’, & Py) Puint’é UY value “eben hap lse, ed ABE Ma ey : MY Sepa eG 1, pleas {I Ge | i ty ive ce Loge eal ce ae eae | ( 4 ms fess) ( Oe yy Abia, 942k) i pee Scorn val ; 1 © scanned with OKEN Scanner a HS Sod oity ys HAD a6) Te 2 yagagy ISL BShna 48 F aa 03 Noose otdade es 974"! > TI 99 Als Hg EA yt lg ie bbn’ Teo iy a3) sg add L WS feony ay pisbey nod BAI. 99% Osa Oe yncuude estdco. ee YS Pdengg Wore me) HAMOPS. MAy vod ea YN Hog eae $3,415 Sam OES RAO cis 9t, FPEVS [ldectayatiert “inte entey arvvay Blame BSN | By AsO SY) ge): ganar FSGS TSEAUEN, Joy cagoug yet Jie Sea by Qa) ia ae4 seane CY dh) aati BHI ony bs SIV Oa soa a os crray | ' “ifcatlratisatier © } YOST oD ya iod tao 999 WHO Che O05 165 3 tA jas sow joes WoWggp: pal (robbins iG § We 4 epea yy s | pert ty ; re A Sagiboe Siphon ant a Lpince t' (n The. sum, ¢s ash S45 i Sydnee aM ‘guy lev avvay atemedlt (4) 31S Ug 54 8. AHR A OAR OR ny © scanned with OKEN Scanner , 4) Pointey td Pointer gurre avin oe A pountey! foo! poenbe yy ts a, for Mmuutiple endive ction, or a chow! t we i Normally , oa poentey contains Address Of Q variable + er A pointer to the pointe , the € contains the addres of the $¢ . whtch potnts to the; tocation. that, Cr pe ag show n contains the acutual vo e ; below - & poenrey : potntey variable _» (padresd} +[veue] PR YDB Jo A variable that is ao PoEteN, © poinee must be declared ag Such: by placing ar addé tional: aseewek front of tes name . For example, the Following dectavation. alg clare 0, Poin bey to a pointey of type int - tnt ** var; when, a, tayget value vs Endive ctty we p> ise rid Pocntect to by & pointer to a porter accessing that Valute! ‘véeutye's: shat astevtk opevatoy be appued tawece , as is Shown, betou n, the Semele ees i beeay Finclucte estdto.hy 1 CARED end CMR VET HET tr svieg int vay; [variable (OE REY) > UpOENEEY, coven + int ** ppty; // Pointer to pointer © scanned with OKEN Scanner 3000 ; PA iG ; : ithe : hao Addl ¥e ws» oF yay, Hn 0 ow bey = Avay j! TASH py oy \ tb donop a ‘take the address og per ubiag’ address Py dh Qeerakoy Re} wit ays p\PPEY = &pEys NY Slum yn unde ¥ a in take the vatue uH0g poy af int? (“value of vay = d\n” pit Pi Many , mintt "value avaiable at ¥ per =. 10", * Ptr)s nint eC value! available ot «per sy ANO”, red; mint? C addres of var = Ko\ny; wvANS mint # Caddvés of pty = 7.0\n", ptr) mide Caddrex of ppth=%UWNl'by ppt) 5 a aed TL cs uepdt 2 |) jae Of Var’ “3000! ‘ Powis oy oy r lie, avaaaite, ot Pee J 3b00 Ww Vobie available a dae | “3000 OH Hod volsg NR Tb soy ay HE dlanise deo 98) Maal as Alypice Sab CNR AV y boy yore » Wn wes © scanned with OKEN Scanner Nutt pointers Pagk ae +) A runt \pocriuer > (sil ah PO” ar does OY noe posnt to any memerd ro | memory pitied y £1.9E. YeRYE sents an, hives py Oe location Cee ana ( ded + x] when a nuic value bs assiga Oa, eee ost Leb dered Pointer , then. the poin Sopy 9.) Stay as Nucl pon ter row, “as faye Vo ood) Vain eg en 3 f THN ory bp Meraigvay osudy ) Bdoney The FARES ese bn Anaiianrn Roe A } eT iF be audio ey i MAIN LPI - coy yu ROOD yan {Or GO a ie fib olf Doin UNE PEPE = NUL Gf) OME EP TINUTG vretuyn 0} Pri Gud”, xP); i ole = 49) is To checkt for NU Pointer, before accestin any , porter, Manabe. co, that - we can iy) Orr extore evr, handdn le. Pocntey PO ea ay hh vetared Code! PL ODWAS Shi. To pass a nut pocatey to a function argument when we don't want to Part it pass’ any Valtd memory Adereds . u © scanned with OKEN Scanner Bh vce, con a ey es de any pep) AN, Can be type edseed /to. and type | int a=zto; hbase blad dy char beX’; wisn 2) va FP = bas. loa pointer ¥ Rdudle adelres op int, alt) 9 «P= kb; Ilvotd pocnter notd’s ‘address of char Bibin t sr OSE, | mauoc ©) and? ¢attece’) ‘meturn Wotd ‘Ftype and thes altows these fanaions PANS oil pointers inc ave Used to Cmplement H Generic functions (HCP! Sol eng igo interns cannot be dereferenced ENedavaly jy yids NG Jiquare Vivi. boy bays LA int azcols VT Rta ty sito} ‘cd €PtY = 40; Pe ney ¥PLY Daa; ja, PUD) NT)” patadle lend) 8 ant *) ety} fade Hoya oy Ms Day ONY eh «SO Sa ei oes) ity’ he allow potntey apithmetic loth void! pocnters - © scanned with OKEN Scanner C4 Oop aya oh beh € Ate | bp Bgyb 17 ota any ne ' oe 3 Loortl ie a 9) BOLD POMP ge i» weld Pointer ¥ 2 eee a va anid be thak HON EMAL Z 4 | wath. any | autres oe "ited? witel Poin e., 2 badd “pdintew! becay,, “lyd de ftsr also now app as i conte, tk holds the address oF vandbot M0 ry ue cation - Jy pb dy Bodie vif Stam? POG Pal cava se Ma Huge ete Pee ra e Pi BH Soy ying Viv d moin { int ¥P 5 LAD BINA prin CK dy PIE in ho DeIAt aybage ValKe,, wh) VN app IAD | pbeays \ Static memory alto “allocation ¢° yas Memory: rato cated during. fomptle time ts ) Caxed., Static memory, MAY yoy The meray, jolla cated 4 Re and cannot WUe be tneveasea ov decreased dust i ng wun time eeu cade» 1 ite : hs, oe) ok ime ated) “Ufc ze aN HCI Bogan ea slts o ibe NONR Vezeay tb © scanned with OKEN Scanner sthe VUES. stored by the useY f \ mit a hee ere yay (S Les than! {hell ize” epect fled Eh @ wlll be wastage of memo: a : (C memory’ 4 MEMAOG) atocaslon sys) yy fe)! process op! attocating memory ab the time ye execeition CvUN time) ts called Aynantce ReMoryy attocation | 81 Vs yh fh os biql vipaoce dure on A can be degnied ° ds hanged Mich the clze of datactmuchare Us C axing the vuntime } ap ts Carl! dveo Joy memory; yp her altocated >! ‘deuterated, én.) any order, ; Provides 4 Worary | functions defined ndey au cdtion. 114 yeattocc) ‘free t) th ig used (to 1d ynanicaty Altocate a “ee ngle vge block of memory" wth the speci fred i e. ak Garde ON ia returns a pointer Of tyPE ‘votd" which, re be cast into a pointer of any — © scanned with OKEN Scanner MSE iniecate cg each lock ; WEY sdhefau, ; ha Vole pow Aw Gap 5 IPL doy eur f per = Cene™*yeauans CHHisaBe AEN): 3). a pA ago IO LE bYEe g VORA Lei ey DiS MAY MoM}, 45 eas i HUNdude € CE dO b>. bs 535 Prana |) ovo) tinelude, gtd Ub. h> fly ad PED) Amc FD maEOOD: rj) dole sa We 31 ee DD pena) SD aris MOR OYA BEYy SEM F055 yoo Print? O'eneew NUMbey OFS Ertag ers"). POH INF ole soso gf SSH |) en Pty = tint ¥) mato 6h FH AFE ORtine); tf (REY = = MUU) Mmemory \annet be allo cated “ADI 9g { {9 20h Wi) Printt Vernon l memory nol ‘atoctite d); {D4 0n oe del Saale e095 Bobo any print, ¢ vemtey, iol oh CD Soe £°C ox a) Histements') jy, ja hehe wah, Peron a) toa 8) beep faba am _ Powe $2 (Dad gpeny “ob rPtvtiy; POA RAB, db 7 830) 420) od pnd a neg © scanned with OKEN Scanner ion Vonbaes syyabon 6 3 piney a, ts Wa" deinsyyiied dit vee (Ptr), |” Ml eget) qa ages sey, humber Of integers § oot Pagers "9 ydnic i 1 ntey elements ( 20 30 4 50 um of elements” ave — Sum ts 150 j CPA Neon ystoe" Qeraieg . Tree asi toon) cot © tS contiguous allocation . method tn ; is used €0 aynamtcaly | elnere ithe Brepticet number of wuoces | oF memory oe rt Wide Saeed rates) QP Wels aute Ctr asi od 1) ead TTT rT wT y= (cast - type *) cauoc cn, element -@ze); = (etoat *) “ealloc CS, etree of toa) synpet sel Leod Tah stone © floako Pato Peakom Foal > © scanned with OKEN Scanner eae ae reco ote ae Be op HF inctude maine 9 Corba ob ae INL 4, ) KRY 9 SUMED? } Printy Center numbey of aements") Sean ft (Aa", 40); Ptr = Ctou*)) calloe cp, tze of Minty), | ig (Ptr = = nuer) Bigs £ rep oso) ia Printe Cevrvor | memory, ‘net. “allocate 4 ) )) Joon ‘ extt (0) 5 j ; Oel 2d) wehbe punt? Center elements”); for(iz orien oi t4) i PAV IN IIB © CysawR vd 4 sean Uy. rab, Bessy 49 J 190m ‘y 19 rod Po ! VUE APE 59 ihn Pynte Cysum oF) elements are”) 5 fov Liz 03 jens tt) t SUM Sum + (PLY At) 5 en } Of t \ Print t ( 7 iii 4 " cum); output + © scanned with OKEN Scanner 493007 ae ( B OY Ve attocation : methgal em © hiv se Wramicauy change the memo Mason oF a A i memory. PREV ously . ota ate | ‘ [4 ry ra 5 . the’ rm. vq y ( -. SOY pre vrousiy | etrocartedl worth the hele of mattoc tony, atto,g 6 5 OEE eent , vealloc can be used to dynamically @attocate Memory. e hm yaad PSEC aed) 1s 3 Pty = Cint *) veattoc (PEY, UX Size of und)5 Cir 195 f 4% ) Act “4 include H includec StdUb AS oy Hy iver / maint ) ret ele ba co MUD ot if / TOE LOPE sas ye OY deg | Punt? Center number of (ntegers") 5 hy Scant UY", 4); ors { cety = = NuU) 2 noces BOM oor) pram 1) ARMED) F819 9h { “memory (s not altocated") ppente © memeny,.G, megatoerte go CUE CO), oat OB) es yg WU risa) Thy © scanned with OKEN Scanner Poe Yi) Print eC" enter elements JJ” ) poy pray begs PPA) he yy on ’ { v tne py oi ale bs ged 8 Oy aye BEET TED OH \ raion y pers tint it) regatloc, (PENS THARE/OF Linty) » Vee epey Lo eds dui) 79 490A ' qu $ \ope 1 hy yor Hivay print e Uo emamory i's) fob" aldcaké a”); ent 60)5 i on } 2 pret Sig DMD 09 Print # Center elements”) for (l=6 5 ve asitt) | #3) bee ny Snag Scant Cyd", per tidy 5 iON I2 >. Ob Print & t* ete ments! AV b)5 foy (505 1295 itt) Aion { prin ya", # ceey BOOS; din { POMEL 68D) AEB 08 SY I4 Age ‘\ Fah 9 x ee Sy “aw ¥ frvee\ method in ci ts Used D efgnamical de- attocate the ee { WALI the memory ‘auiocoted sing functions matioce) and cattecc> e¢ not’ de allocal ON thety Own, LOUIE CF Qe) + bag © scanned with OKEN Scanner 1 the freee) eee ee a Siw thy Meth is. used He dynamec Od ¢. ‘A “Tt helps Memory attocotie eahe © reduce waltlge of ory by freeing it | as Vay Ne fi (Pty); painter Ponting tm o Inemori tcator arcs been deteted con (ereed) is called Gung Pointer 4 dangung pointer is a pointer whech points 0 yo perse bute ae , add7e® PO emory Lent spect Fee th [ F . tnt PLT = (int #) matioc Cstze oF Lent) 5 Tucng mattoc, to allocare Some memory, Uting freec) funceton, to release the memory herve, the pointer (Pty) Cs stil pointing the de-autocated memory Thar potnter Ce ed dangung pointer. © scanned with OKEN Scanner So P ' TF imeie ; 1yad co ‘ } me Pty = CE! BY) MONEE CM LE OF rm .} pty = wus —> Now, PEY ES m0 | { dangung > ' Baa ee The, pointer Pointing ba toca Vavear bee becomes dangung when local Ver able not Stakic . “ prseu@ed (n functions Concept af Syas © scanned with OKEN Scanner roy 13 oI ‘tS ected, , the) compiler cakes (6S base Qddvess and surmaent Unt OF ctowage to contain aut the element! ae OV YOY. bd basa base adevess (5 the (ecaon'’ ofthe PiTSt ent OF an array. , na! avvau name Pointer tol “the seve element p ; i int “(5) = (Oui asap 5 Le Ha x eet, x07 xc x ear x97, x Hwy Vole >) 9 ML teh hig actrees —> L000 10082 fooy LONG I1008 * ra « Pase Address ppv) rns") 4 dabe9 WETS mame % tS depined, as a Constant inter Pornting © the ftvSt cement X = & XCO) i = (O00 2 Jung due you can declave P ts an crivegey pointer we can mate the! pointer ‘¢2 awigned -avyay as 83). a tnt = xCS) = (0.111, BL ys int ¥P solar Oe tyo9 © RRLOo4 549 Yan) + 099 OY? P2R5 © scanned with OKEN Scanner y iA CS decteved, » the) compiler — 4 cates (LS base acre gs and surcent £ OF storage to Contain aut the elements an array i haan Ht Nan) Orroy base adedvess % the (cation of the PiTst compiler alse ‘degines’ the! array) name SO (CONS tant potest’ tol The syst element nt “x(5} = CC ESS j ot xtol xed X02 xt3y xo | value —| wo) tod sti addvees —> tooo 10082 tooy 1006 | 1008 ; b a ae ee e he name xis depined 1@S_ & Constant intey pointing to. the fevst element te : X = & xCo} = (000 $ Juaduc you can declare P ts an cntegey ‘pointer ; we can mace the’ pointy pp ‘cg atigned ‘arvay as v9 PRY af tnt = xtS) = (tera tS, yy int #P salal yee EY eR RLOV 5 i9 09) 10121, agp na Pees © scanned with OKEN Scanner “Ve a program 40, COMPULG EE) o, Clements’ stpved in an) GETNAME % Potnteys. | ) ) : 4 male 98 H include eStdto-hs Maine ) { tnt sSum=o, t=o) ¥P3, yo tot x51 {to, 20,130.80) Sof 5 Pe x; while Cres) 1, { Puneet" Xtrdd rd eon” ely *P,P); 3 said gdm / sun + ¥P; Ors F! yoo soag7' 99) « varht Pte; t Zev bho 8 vent. Printe (“sum of elements ¢s 4 di”, » Sum); PAINE? C* base ade os te” 0x0) ; in, by Dok Boy vy OD: } tore of Ro” 209) OWEPUE : Holt BO 24 4 orpish ADD Qo COD gq MBioy (00) oxnMy wip’ og en 2 oy ynrro 2 a 30 "60a | e335 Eade! Mele ye XTHJ 50 tetes ay say sum of elements / 150) Base addyves tsiugon i eae ' 5 © scanned with OKEN Scanner Sf we ~ Hey MS ED Oynays ¢ nteys Can be used to manipulate 9 ays OS cory 1rd array x expression ce aiy (on -¥ (PAL) epre sents e@ elements x C7 , epyesented by pllOw s the potntey cxpretsiion &© *(*catiraj) tor) ¥ (KepHodyy Oy 2 3) i 9 Pp t ed 2 PH? - 3/80 (aay t pd at 7 P+4y (P43) — 5 PIS ¥* (PAZ) 42 > Pont to the It row > pont to the ith row (Pi) — point to the (84 etement tn the i ao- 445) > Pont to the jth etement tn (eyi4s) » Value stored in cett tty5) © scanned with OKEN Scanner

You might also like