欢迎来到天天文库
浏览记录
ID:58193668
大小:1.56 MB
页数:122页
时间:2020-09-05
《C语言学习第七章(英文版)课件.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Chapter7Pointers7.1Introduction7.2PointerVariableDeclarationsandInitialization7.3PointerOperators7.4CallingFunctionsbyReference7.5PointerExpressionsandPointerArithmetic7.6Pointersand1-DArrays7.7Pointersand2-DArrays7.8ArraysofPointers7.9PointerstoPointersOutlinePointerVariableDeclaratio
2、nsandInitializationPointerOperatorsCallingFunctionsbyReferencePointersand1-DArraysPointersand2-DArraysKeyPoints7.1IntroductionPointersPowerful,butdifficulttomasterSimulatecall-by-referenceCloserelationshipwitharraysandstrings7.1IntroductionWhatisapointer?HowmemoryisorganizedinPC?Atypic
3、almachinehasanarrayofconsecutivelynumberedoraddressedmemorycellsthatmaybemanipulatedindividuallyorincontiguousgroups.Apointerisagroupofcells(oftentwoorfour)thatcanholdanaddress.7.1IntroductionAvariableinaprogramisstoredinacertainnumberofbytesataparticularmemorylocationinthemachine.inta
4、;charch;Eachpieceofmemoryshouldhaveadistinctnumberwithit,namedaddress.Canmemorybeaccessedbyitsaddress?FFC1FFC2FFC3FFC4FFC5FFC6ach7.2PointerVariableDeclarationsandInitializationPointervariablesContainmemoryaddressesastheirvaluesNormalvariablescontainaspecificvalue(directreference)Pointe
5、rscontainaddressofavariablethathasaspecificvalue(indirectreference)Indirection–referencingapointervaluecount7count7countPtr7.2PointerVariableDeclarationsandInitializationPointerdeclarations*usedwithpointervariablesint*myPtr;Declaresapointertoanint(pointeroftypeint*)Multiplepointersrequ
6、ireusinga*beforeeachvariabledeclarationint*myPtr1,*myPtr2;CandeclarepointerstoanydatatypeInitializepointersto0,NULL,oranaddress0orNULL–pointstonothing(NULLpreferred)7.3PointerOperators&(addressoperator)Returnsaddressofoperandinty=5;int*yPtr;yPtr=&y;/*yPtrgetsaddressofy*/yPtr“pointsto”y
7、yPtry5yptr500000600000y6000005Addressofyisvalueofyptr7.3PointerOperators*(indirection/dereferencingoperator)Returnsasynonym/aliasofwhatitsoperandpointsto*yptrreturnsy(becauseyptrpointstoy)*canbeusedforassignmentReturnsaliastoanobject*yptr=7;/*changesyto7*/Dereferencedpointer(operando
此文档下载收益归作者所有