欢迎来到天天文库
浏览记录
ID:51212786
大小:259.50 KB
页数:34页
时间:2020-03-20
《二办理复学流程.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Chapter7-PointersOutline7.1Introduction7.2PointerVariableDeclarationsandInitialization7.3PointerOperators7.4CallingFunctionsbyReference7.5UsingtheconstQualifierwithPointers7.6BubbleSortUsingCallbyReference7.7PointerExpressionsandPointerArithmetic7.8TheRelationshipbetweenPointersandArrays7
2、.9ArraysofPointers7.10CaseStudy:ACardShufflingandDealingSimulation7.11PointerstoFunctions7.1IntroductionPointersPowerful,butdifficulttomasterSimulatecall-by-referenceCloserelationshipwitharraysandstrings7.2PointerVariableDeclarationsandInitializationPointervariablesContainmemoryaddressesa
3、stheirvaluesNormalvariablescontainaspecificvalue(directreference)Pointerscontainaddressofavariablethathasaspecificvalue(indirectreference)Indirection–referencingapointervaluecount7count7countPtr7.2PointerVariableDeclarationsandInitializationPointerdeclarations*usedwithpointervariablesint*
4、myPtr;Declaresapointertoanint(pointeroftypeint*)Multiplepointersrequireusinga*beforeeachvariabledeclarationint*myPtr1,*myPtr2;CandeclarepointerstoanydatatypeInitializepointersto0,NULL,oranaddress0orNULL–pointstonothing(NULLpreferred)7.3PointerOperators&(addressoperator)Returnsaddressofope
5、randinty=5;int*yPtr;yPtr=&y;//yPtrgetsaddressofyyPtr“pointsto”yyPtry5yptr500000600000y6000005Addressofyisvalueofyptr7.3PointerOperators*(indirection/dereferencingoperator)Returnsasynonym/aliasofwhatitsoperandpointsto*yptrreturnsy(becauseyptrpointstoy)*canbeusedforassignmentReturnsaliastoa
6、nobject*yptr=7;//changesyto7Dereferencedpointer(operandof*)mustbeanlvalue(noconstants)*and&areinversesTheycanceleachotherout1.Declarevariables2Initializevariables3.PrintProgramOutput1/*Fig.7.4:fig07_04.c2Usingthe&and*operators*/3#include45intmain()6{7inta;/*aisaninteger*/8int*aPt
7、r;/*aPtrisapointertoaninteger*/910a=7;11aPtr=&a;/*aPtrsettoaddressofa*/1213printf("Theaddressofais%p"14"ThevalueofaPtris%p",&a,aPtr);1516printf("Thevalueofais%d"17"Thevalueof*aPtris%d",a,*aPtr);1819printf("Showingthat*and&areinversesof"20"eachother.&*a
此文档下载收益归作者所有