




已阅读5页,还剩27页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
.,Chapter3OperatorsandExpressions,PROGRAMMINGINANSIC,.,Operators,.,Expressions,Anexpressionisasequenceofoperandsandoperatorsthatproducesasinglevalue.Thisvaluemaybeanydatatypeexceptvoid.,.,Howtolearnoperatorsandexpressions?,Whenwestudyoperatorsandexpressions,wemustpayattentiontosuch5points:Thefunctionofoperators.Therelationofoperatorsandoperands:Howmanyoperandsdoestheoperatorneed?Whichtypesdoestheoperatorrequire?Theprecedenceoftheoperator.Theassociativityoftheoperator.Thetypeofthecalculatedresult.,.,ArithmeticOperatorsCdoesntsupplyexponentialoperator,soyoucanwritesomemultiplication,oryoucanusemathematicfunctionpow(x,y)intheCfunctionlibrarytoexpressxy;Noticetheprecedenceofthosearithmeticoperators,andyoushouldreasonablyuseparentheses.,.,ArithmeticOperatorsb=a*3.0;Dontmakeanyexpressiondividezero.Avoiddataoverflow.,.,RelationalOperatorsabc=ababf=abc,32,thevalueis11=1,thevalueis1b+c=3,thevalueis0d=1abis1,1cis0,so:f=0,.,RelationalOperatorsinta=b=5;Wrong!inta=5,b=5;Right!,.,AssignmentOperatorsa=b=c=5;a=5+(c=6);a=(b=4)+(c=6);,c=5,b=c,a=b/*a=5,b=5,c=5*/c=6,a=5+c/*a=11,c=6*/b=4,c=6,a=b+c/*a=10,b=4,c=6*/,.,AssignmentOperatorsisequivalentto:variable=variableopexpressione.g.x*=y+1;isequivalentto:x=x*(y+1);,.,AssignmentOperatorsa+=a-=a*a;,a+=a=4a+=(a=a4)a+=(a=-2)a+=aa=a+aa=(-2)+(-2)a=-4,.,IncrementandDecrementOperators,+-m+;or+m;isequivalentto:m=m+1;m-;or-m;isequivalentto:m=m-1;Precedence:sameasunary+,unary-,!Associativity:Righttoleft,(10/m)+Wrong!10/m+Right!,.,IncrementandDecrementOperators,intm=5,n;n=10/m+;isequivalentto:n=10/m;m+;n=10/+m;isequivalentto:+m;n=10/m;,.,IncrementandDecrementOperators,j=3;k=+j;j=3;k=j+;j=3;printf(%d,+j);j=3;printf(%d,j+);a=3;b=5;c=(+a)*b;a=3;b=5;c=(a+)*b;,j=j+1;k=j;result:k=4,j=4k=j;j=j+1;result:k=3,j=4j=j+1;printf();output:4printf();j=j+1;output:3a=a+1;c=a*b;result:a=4,c=20c=a*b;a=a+1;result:a=4,c=15,.,IncrementandDecrementOperators,NoticeTheoperandof+or-mustbeavariableandnotanyexpressionoranyconstant.,.,CommaOperatorb=(a=3*4,5*2);a=1;b=2;c=3;printf(%d,%d,%d,a,b,c);printf(%d,%d,%d,(a,b,c),b,c);,a=12a=12,b=10output:1,2,3output:3,2,3,.,ImplicitTypeConversion,Therulesofconversion:P67Inallexpressionsexceptassignments,anyimplicittypeconversionsaremadefromalowersizetypetoahighersizetypeasshownhere:,.,ImplicitTypeConversion,Duringassignment:Ifexpressionisrealtypeandthevariableisintegertype,thevalueofexpressionwillbetruncateditsfractionalpart.Ifexpressionisdoubletypeandthevariableisfloattype,thevalueofexpressionwillberounditsdigits.Ifexpressionislongtypeandthevariableisinttype,thevalueofexpressionwillbedropitshigherbyte.,.,ImplicitTypeConversion,inti,x;floatf;doubled;longL;x=L/i+i*f-d;,long,float,float,float,double,double,double,int,Notice:inthewholeprocessoftypeconversion,onlythetypeoftheinterimvalueusedinevaluationisconverted,butallthetypesofvariablesarenotconverted.Exceptthevariable“x”assignedavalue,allthevaluesofothervariablesarenotchanged.,.,ExplicitTypeConversion,Form:(type-name)expressionPrecedence:sameasunary+,unary-,!,+,-Associativity:Righttolefte.g.(int)(x+y)(int)x+y,main()floatx,y;x=3.6;y=(int)x*2;printf(x=%.2f,y=%.2f,x,y);,x=3.60,y=6.00,Notice:liketheimplicittypeconversion,onlythetypeoftheinterimvalueusedinevaluationisconverted,butallthe
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 系统分析设计方法
- 2025年宠物训导师应急处理能力测试卷:实操案例分析及对策
- 2025年外贸跟单员职业资格考试试卷:外贸跟单员国际贸易企业竞争策略试题
- 2025年云南省事业单位招聘考试综合类专业能力测试试卷(法律类)实战演练
- 2025年医保支付方式改革考点试题汇编试卷
- 读懂青春作文800字青春作文8篇
- 2025年安全生产风险分级管控考试大纲解读与试题解析
- 2025年中式面点师(八十一级)考试试卷与美食反馈
- 2025年中式面点师(初级)考试试卷:中式面点制作技艺实践操作
- 缘于生命的伟大力量读有感500字(15篇)
- 建平磷铁矿业有限公司磷(含磁铁磷灰石)矿矿山地质环境保护与土地复垦方案
- DB22∕T 3181-2020 公路水路行业安全生产风险分级管控和隐患排查治理双重预防机制建设通用规范
- GB/T 36713-2018能源管理体系能源基准和能源绩效参数
- GB/T 25068.1-2020信息技术安全技术网络安全第1部分:综述和概念
- “二级甲等妇幼保健院”评审汇报材料
- 《狼王梦》读书分享PPT
- 三年级美术下册第10课《快乐的节日》优秀课件1人教版
- 电力市场交易模式
- 第四课《单色版画》 课件
- 门诊手术麻醉原则课件
- 自动喷水灭火系统质量验收项目缺陷判定记录
评论
0/150
提交评论