c语言第x章函数重庆交大版.ppt

  1. 1、本文档共74页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
c语言第x章函数重庆交大版

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 3、取消宏定义(#UNDEF) 取消宏定义命令#undef的用法格式为:#undef 标识符 例: #include stdio.h #define PI 3.14159 void main() { float r=10.0; float b,c,d; b=PI*r; #undef PI /*取消了宏定义*/ c=PI*r*r; d=PI*r*r*r; printf(“r=%6.2f\n”,r); printf(“b=%6.2f\nc=%6.2f\nd=%6.2f\n”,b,c,d); } * Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 4、宏定义与函数的区别 引用宏只占编译时间,不占运行时间。 引用宏没有返回值。 如: #define squ(n) n*n main() { printf ("%f\n",27.0/squ(3.0)); } 程序输出结果为: 27.000000 * Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 宏替换的形参无类型。 实参为表达式: 函数调用是先计算出实参的值, 再将值传递给形参;宏的引用是用表达式替换形参。 例如: 定义:#define S (a,b) a*b 引用: S(a+c,b+c) 展开: a+c*b+c * Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 4.4.3 文件包含 文件包含#include : 一个源文件可以将另一个源文件的全部内容包含进来。 #include命令有两种格式。 (1) #include 文件名 (2) #include “文件名” * Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 4.4.4 条件编译 1 控制条件为常量表达式的条件编译 形式一: #if 常量表达式 程序段 #endif 功能: 常量表达式非0时,程序段被编译。否则程序段不被编译。 * 形式二: #if 常量表达式 程序段1 #else 程序段2 #endif 功能: 常量表达式为非0时,程序段1被编译。否则,编译程序段2 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 嵌套形式: #if 常量表达式1    程序段1 #elif 常量表达式2 程序段2    ...... #elif 常量表达式n 程序段n   #else   程序段n+1   #endif * Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 例: #include stdio.h #define R 1 void main() { float c,r,s; printf (input a number: ); scanf(%f,c); #if R r=3.14159*c*c; printf(area of round is: %f\n,r); #else s=c*c; printf(area of square is: %f\n,s); #endif }

文档评论(0)

383947923 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档