- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
Chapter 7 - Functions 7.1 Introduction Divide and Conquer ——分而治之 Construct a program from smaller pieces or components Each piece more manageable than the original program 函数是一段完成特定任务的程序。 模块化程序设计 基本思想:将一个大的程序按功能分割成一些小模块 特点: 各模块相对独立、功能单一、结构清晰、接口简单 控制了程序设计的复杂性 提高元件的可靠性 缩短开发周期 避免程序开发的重复劳动 易于维护和功能扩充 开发方法: 自上向下,逐步分解,分而治之 7.2 Program Modules in C Functions Modules in C Programs written by combining user-defined functions with library functions C standard library has a wide variety of functions Makes programmers job easier - avoid reinventing the wheel 7.2 Program Modules in C (II) Function calls——函数调用 Invoking functions——调用函数 Provide function name and arguments (data) Function performs operations or manipulations Function returns results Boss asks worker to complete task Worker gets information, does task, returns result Information hiding: boss does not know details 7.3 Math Library Functions Math library functions perform common mathematical calculations #include math.h Format for calling functions FunctionName (argument); If multiple arguments, use comma-separated list printf( %.2f, sqrt( 900.0 ) ); Calls function sqrt, which returns the square root of its argument All math functions return data type double Arguments may be constants, variables, or expressions 7.4 Functions Functions Modularize a program All variables declared inside functions are local variables(局部变量) Known only in function defined Parameters Communicate information between functions Local variables Benefits Divide and conquer Manageable program development Software reusability Use existing functions as building blocks for new programs Abstraction - hide internal details (library functions) Avoids code repetition 7.5 Function Definitions Function definition format return-value-type function-name( parameter-list ){ declarations and statements} Function-name: any valid identifier Return-value-type: data type of the result (default int) void - function returns nothing Parameter-list: com
文档评论(0)