C语言基础教程课件(英文版)ch14.ppt
- 【下载声明】
1. 本站全部试题类文档,若标题没写含答案,则无答案;标题注明含答案的文档,主观题也可能无答案。请谨慎下单,一旦售出,不予退换。
2. 本站全部PPT文档均不含视频和音频,PPT中出现的音频或视频标识(或文字)仅表示流程,实际无音频或视频文件。请谨慎下单,一旦售出,不予退换。
3. 本页资料《C语言基础教程课件(英文版)ch14.ppt》由用户(晟晟文业)主动上传,其收益全归该用户。163文库仅提供信息存储空间,仅对该用户上传内容的表现方式做保护处理,对上传内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知163文库(点击联系客服),我们立即给予删除!
4. 请根据预览情况,自愿下载本文。本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
5. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007及以上版本和PDF阅读器,压缩文件请下载最新的WinRAR软件解压。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 基础教程 课件 英文 ch14
- 资源描述:
-
1、A First Book of ANSI CFourth EditionChapter 14Additional CapabilitiesA First Book of ANSI C,Fourth Edition2Objectives Additional Features Bit Operations Macros Command-Line Arguments Common Programming and Compiler ErrorsA First Book of ANSI C,Fourth Edition3Additional Features The typedef declarati
2、on statement Conditional preprocessor directives Enumerated constants Conditional expressions The goto statementA First Book of ANSI C,Fourth Edition4The typedef Declaration Statement typedef permits constructing alternate names for an existing C data type name typedef double REAL;makes the REAL an
3、alias for double REAL val;is equivalent to double val;typedef does not create a new data type The equivalence produced by typedef can frequently be produced equally well by#define typedef processed by the compiler#define processed by the preprocessorA First Book of ANSI C,Fourth Edition5The typedef
4、Declaration Statement(continued)Another example:typedef int ARRAY100;ARRAY first,second;Equivalent to the two definitions int first100;and int second100;As another example:typedef struct char name20;int idNum;empRecord;empRecord employee75;A First Book of ANSI C,Fourth Edition6Conditional Preprocess
5、or Directives#ifndef and#ifdef permit conditional compilation in that the statements immediately following these directives,up to an#else or#endif,are compiled only if the condition is true,whereas the statements following the#else are compiled only if the condition is false For example,#ifndef cond
6、ition compile the statements placed here#else compile the statements placed here#endifA First Book of ANSI C,Fourth Edition7Conditional Preprocessor Directives(continued)The#else directive is optional#ifndef is the most frequently used conditional preprocessor directive Its most common usage is in t
7、he form#ifndef header-file#include#endif For example:#ifndef stdio.h#include#endifA First Book of ANSI C,Fourth Edition8Enumerated Constants Set of related integer values can be equated to an equivalent set of constants using an enumerated list enum Mon,Tue,Wed,Thr,Fri,Sat,Sun;By default,the first e
8、numerated name in an enumerated list has a value of 0 The enumeration above is equivalent to:#define Mon 0#define Tue 1#define Wed 2 A First Book of ANSI C,Fourth Edition9Enumerated Constants(continued)To specify the value of the first enumerated name:enum Mon=1,Tue,Wed,Thr,Fri,Sat,Sun;Any integer c
9、onstant can be equated to enumerated names;they need not be in sequence,and an optional enumerated list name can be used enum escsequences BELL=a,BACKSPACE=b,NEWLINE=n,RETURN=r,TAB=t;Enumerated constants can be any valid user-created identifier,but each name must be unique OK for two constants to be
10、 equated to the same integer valueA First Book of ANSI C,Fourth Edition10Conditional Expressions A conditional expression uses the conditional operator,?:and provides an alternate way of expressing a simple if-else statement expression1?expression2:expression3 For example,the if-else statementif(hou
11、rs 40)rate=0.045;else rate=0.02;Can be replaced withrate=(hours 40)?0.045:0.02;?:is unique in C in that it is a ternary operatorA First Book of ANSI C,Fourth Edition11Conditional Expressions(continued)Conditional expressions are only useful in replacing if-else statements when the expressions in the
12、 equivalent if-else statement are not long or complicated For example,the statement maxVal=a b?a:b;is a one-line statement that assigns the maximum value of the variables a and b to maxVal A longer,equivalent form of this statement isif(a b)maxVal=a;else maxVal=b;A First Book of ANSI C,Fourth Editio
13、n12The goto Statement goto provides an unconditional transfer of control to some other statement in a program goto label;label is any unique name chosen according to the rules for creating variable names For example,if(denom=0.0)goto err;else result=num/denom;.err:printf(Error:Attempted Division by
14、Zero);A First Book of ANSI C,Fourth Edition13The goto Statement(continued)Generally,it is much easier to call an error routine for unusual conditions or use a break statement if this is necessary,rather than use a goto Theoretically,a goto is never required because Cs normal structures provide suffi
15、cient flexibility to handle all possible flow control requirements gotos tend to complicate programs Using even one goto statement in a program is almost always a sign of bad programming structureA First Book of ANSI C,Fourth Edition14Bit OperationsA First Book of ANSI C,Fourth Edition15The AND Oper
16、ator&causes a bit-by-bit AND comparison between its two operands AND operations are extremely useful in masking,or eliminating,selected bits from an operand For example,The 0s in op2 effectively mask the respective bits in op1,while the ones in op2 filter the respective bits in op1 through with no c
17、hange in their values In this example,op2 is called a maskA First Book of ANSI C,Fourth Edition16The AND Operator(continued)Program 14.1 produces the following output:325 ANDed with 263 is 221A First Book of ANSI C,Fourth Edition17The Inclusive OR Operator The result of an inclusive OR(|)bit compari
18、son is 1 if either bit is a 1;otherwise the result is a 0 Inclusive OR operations are extremely useful in forcing selected bits to take on a 1 value or for passing through other bit values unchanged For example,ORing with a 0 has the same effect as ANDing with a 1A First Book of ANSI C,Fourth Editio
19、n18The Inclusive OR Operator(continued)Program 14.2 produces the following output:325 ORed with 263 is 367A First Book of ANSI C,Fourth Edition19The Exclusive OR Operator The result of an exclusive OR()comparison is 1 if one and only one of the bits being compared is a 1;otherwise the result is 0 An
20、 exclusive OR operation can be used to create the opposite value,or complement,of any individual bit in a variable For example,A First Book of ANSI C,Fourth Edition20The Complement Operator is the unary complement operator If op1 contains the binary number 11001010,op1 replaces this number with 0011
展开阅读全文