C语言李凤霞版指针第九章课件

C语言李凤霞版指针第九章课件

ID:44210474

大小:841.50 KB

页数:63页

时间:2019-10-19

C语言李凤霞版指针第九章课件_第1页
C语言李凤霞版指针第九章课件_第2页
C语言李凤霞版指针第九章课件_第3页
C语言李凤霞版指针第九章课件_第4页
C语言李凤霞版指针第九章课件_第5页
资源描述:

《C语言李凤霞版指针第九章课件》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、Chapter9:PointersInstructor:DandanSong100110011100101010001100000010111100101010001100Address00010002000310231024Canaddressstoreinmemory?Whyshouldaddressstoreinmemory?Outline9.1BasicsofPointers9.2ArrayandFunction9.3PointerandFunction9.4PointerandArray9.5PointstoaPointer

2、Whatisapointer(指针)?---Apointerisavariablethatcontainstheaddressofavariable.HowmemoryisorganizedinPC?---Atypicalmachinehasanarrayofconsecutivelynumberedoraddressedmemorycellsthatmaybemanipulatedindividuallyorincontiguousgroups.Apointerisagroupofcells(oftentwoorfour)thatc

3、anholdanaddress.9.1BasicsofPointersEg:inta,*p;p=&a;/*pointervariablepstoresaddressofa*/直接访问(Directaccess)通过变量名访问该变量。间接访问(Indirectaccess)通过指针变量中存放的地址访问该变量inta=10;printf(“%d”,a);inta=10,*p=&a;printf(“%d”,*p);定义变量:intk;编译系统根据int为k分配内存单元。输入变量的值:scanf(“%d”,&k);&k代表了变量k在内

4、存中的地址。变量pk是一个指针变量,存放k的地址,称”指向k”100intk=100;&k=2008H2008Hint*pk=&k;指针就是地址!指针变量就是存放地址的变量!Basicconceptsmain(){inta,b,c;a=5,b=10;c=a+b;printf(“%d,%d,%d”,a,b,c);}main(){inta,b,c,*pc;a=5,b=10;pc=&c;c=a+b;printf(“%d,%d,%d”,a,b,*pc);}/*Directaccessc*//*Indirectaccesscbypointerp

5、c*/Compare:指针可以指向所有类型的数据指针指向变量--变量的指针(存变量的地址)指针指向数组--数组的指针(存数组的起始地址)指针指向函数--函数型指针(存放函数的入口地址)指针指向指针--指针型指针(存放某指针的地址)由指针组成的数组--指针数组指针是定位其他数据类型的特殊类型的数据(存放其他数据的地址)Data_type*pointer_name[=initial_value]BasictypeData_typeisthevariabletypepointerpointsto;*ispointerindication,i

6、ndicatesapointervariable(alsoanindirectaccessoperator)inta,*pa;pa=&a;//pacanonlypointstoaninteger*pa=10;//indirectaccessa,a=10;inta,*pa=&a;DefinitionandInitialization*addressgetvariablecontentintheaddressinta=5,*p;p=&a;/*givepa’saddress*/a=10+*p;/*equalsa=10+a*/*p*(&a)

7、adefinitionOperationUsingofapointermain(){inta,b,c,d,e,*pa=&a,*pb=&b,*pc,*pe;pc=&c;pe=&e;scanf(“%d,%d”,&a,pb);/*input10,20*/c=a+b;/*c=30*/d=*pa+*pb;/*d=a+b,d=30*/e=*pc;/*e=c=30*/printf(“%d,%d,%d,%d”,c,d,e,*pe+1);}输出:30,30,30,31Therearethreekindsofbasicoperationsforpo

8、inter:Additionoperationandsubtractionoperationbetweenapointerandapositiveinteger.Relationaloperationbetweentwo

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。