- 1、本文档共40页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Chapter5-PointersandStrings:5章指针和字符串.ppt
Chapter 5 - Pointers and Strings 5.1 Introduction Pointers Powerful, but difficult to master Simulate pass-by-reference Close relationship with arrays and strings 5.2 Pointer Variable Declarations and Initialization Pointer variables Contain memory addresses as values Normally, variable contains specific value (direct reference) Pointers contain address of variable that has specific value (indirect reference) Indirection Referencing value through pointer Pointer declarations * indicates variable is pointer int *myPtr; declares pointer to int, pointer of type int * Multiple pointers require multiple asterisks int *myPtr1, *myPtr2; 5.2 Pointer Variable Declarations and Initialization Can declare pointers to any data type Pointer initialization Initialized to 0, NULL, or address 0 or NULL points to nothing 5.3 Pointer Operators (address operator) Returns memory address of its operand Example int y = 5;int *yPtr;yPtr = y; // yPtr gets address of y yPtr “points to” y 5.3 Pointer Operators * (indirection/dereferencing operator) Returns synonym for object its pointer operand points to *yPtr returns y (because yPtr points to y). dereferenced pointer is lvalue *yptr = 9; // assigns 9 to y * and are inverses of each other fig05_04.cpp(1 of 2) 1 // Fig. 5.4: fig05_04.cpp 2 // Using the and * operators. 3 #include iostream 4 5 using std::cout; 6 using std::endl; 7 8 int main() 9 { 10 int a; // a is an integer 11 int *aPtr; // aPtr is a pointer to an integer 12 13 a = 7; 14 aPtr = a; // aPtr assigned address of a 15 16 cout The address of a is a 17 \nThe value of aPtr is aPtr; 18 19 cout \n\nThe value of a is a 20 \nThe value of *aPtr is *aPtr; 21 22 cout \n\nShowing that * and are inverses of 23 each other.\n*aPtr = *aPtr 24 \n*aPtr = *aPtr endl; 25 fig05_04.cpp(2 of
您可能关注的文档
- BASICInjectionMolding:基本的注射成型.pdf
- BASS预测模型与库存控制集成研究.pdf
- BaTiO3颗粒对分散剂PMAA—NH4的吸附机制研究.pdf
- BatteryMon使用方法详解.pdf
- ba于双向变流技术的蓄电池充放电装置.pdf
- BehavioralAssessment:行为评估.ppt
- BehavioralCorrelatesofSleepPathologyAmongObeseTee:行为相关的肥胖TEE睡眠病理学.ppt
- BenefitsofCoverCropstoProductivity,Tilth,andHealth:效益的覆盖作物的生产力,耕作,与健康.pdf
- bf真程序EMTP在电力系统继电保护中的应用.pdf
- BGPConditionalRouteInjection-CiscoSystems:BGP路由注入思科系统的条件.pdf
最近下载
- TBIE 004—2023通孔回流焊接技术规范团标.pdf
- 国开《MySQL数据库应用》形考1-4(试题及答案).pdf VIP
- 煤矿安全生产作业规程操作规程安全技术措施编制审批贯彻及执行管理制度.doc
- 2020年光学膜行业研究报告.pdf
- 采血管种类和应用ppt课件.pptx VIP
- 职业生涯报告六篇.pdf VIP
- Unit 4 Plants arounds us PartA Let's talk(课件)人教PEP版(2024)英语三年级上册.pptx
- 七年级上册生物:必考问答式知识点汇总(背诵+默写).docx
- 《青纱帐——甘蔗林》课件【中职专用】高教版 基础模块下册.pptx
- 国家开放大学学位英语历年真题试卷号1909.docx
文档评论(0)