欢迎来到麦多课文档分享! | 帮助中心 海量文档,免费浏览,给你所需,享你所想!
麦多课文档分享
全部分类
  • 标准规范>
  • 教学课件>
  • 考试资料>
  • 办公文档>
  • 学术论文>
  • 行业资料>
  • 易语言源码>
  • ImageVerifierCode 换一换
    首页 麦多课文档分享 > 资源分类 > PPT文档下载
    分享到微信 分享到微博 分享到QQ空间

    C Programming.ppt

    • 资源ID:372888       资源大小:1,003KB        全文页数:26页
    • 资源格式: PPT        下载积分:2000积分
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    二维码
    微信扫一扫登录
    下载资源需要2000积分(如需开发票,请勿充值!)
    邮箱/手机:
    温馨提示:
    如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如需开发票,请勿充值!如填写123,账号就是123,密码也是123。
    支付方式: 支付宝扫码支付    微信扫码支付   
    验证码:   换一换

    加入VIP,交流精品资源
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    C Programming.ppt

    1、C Programming,Lecture 5,Precedence and Associativity of Operators,Rules of associativity and precedence of operators determine precisely how expressions are operated. In the expression 1 + 2 * 3, the operator * has higher precedence than +, causing the multiplication to be performed first. The resul

    2、t is 7 instead of 9.,Associativity of Operators,When two operators placed in proximity in an expression have the same precedence, their associativity is used to determine how the expression is evaluated. In the expression 6 / 2 * 3, both / and * have the same precedence. Since they both have left to

    3、 right associa-tivity, the expression has the value 9 rather than 1.,Partial Table of Operator Precedence and Associativity,Operator Associativity,() + (postfix) - (postfix) left to right+(unary) -(unary) +(prefix) -(prefix) right to left* / % left to right+ - left to right= += -= right to leftOpera

    4、tors on the top line have the highest precedence.Precedence decreases line-by-line going down the table.All operators on the same line have equal precedence.,Parentheses and the Order of Operations,Expressions inside parentheses are evaluated first. This provides for the use of parentheses to clarif

    5、y or change the order in which operations are performed.1 + 2 * 3 has a value of 7.(1 + 2)* 3 has a value of 9.,Binary Plus versus Unary Plus,Both binary plus and unary plus are represented by a + (plus sign). The same is true of binary and unary - (the minus sign). Unary + and - have a higher prece

    6、dence that binary + and - and the unary operators associate right-to-left instead of left-to-right.,Example of Unary Operators,In the expression - a * b - c the first minus is unary and the second is binary. We can use parentheses to write an equivalent expression that is less likely to be misinterp

    7、reted.(- a) * b) - c,Example of Unary Operators Using Numbers,-1 * 2 - 3 has a value of -5 it is equivalent to(-1) * 2) - 3 or (-2) - 3which is -5 it is not equivalent to(-1) * (2 - 3) or (-1) * (-1)which is +1,Increment and Decrement Operators,+ (the increment operator) and - (the decrement operato

    8、r) are unary operators with the same precedence and right-to-left associativity as the other unary operators. The + and - operators can occur in either a prefix or postfix position with different results.,Prefix versus Postfix When Using Increment and Decrement Operators,Each of the expressions +i a

    9、nd i+ causes the stored value of i to be incremented by 1, however: The expression +i causes the stored value of i to be incremented first, with the expression then taking as its value the new stored value of i. The expression i+ has as its value the current value of i; then the stored value is incr

    10、emented.,Example of the Increment and Decrement Operators,int a, b, c = 0; a = +c; b = c+; printf(“%d %d %dn”, a, b, +c);/* 1 1 3 is printed */c is incremented making its value 1.The result assigned to a making its value 1.The value of c is assigned to b making its value 1.Then c is incremented maki

    11、ng its value 2.Finally, c is incremented before it is printed, making its value 3.,Practice with Operators and Expressions,Declarations and Initializations,int a = 1, b = 2, c = 3, d = 4;,Expression Equivalent expression Valuea * b / c (a * b) / c 0a * b % c + 1 (a * b) % c) + 1 3+a * b - c - (+a) *

    12、 b) - (c-) 17 - -b * +d 7 - (-b) * (+d) 17,Partial Table of Operator Precedence and Associativity,Operator Associativity,() + (postfix) - (postfix) left to right+(unary) -(unary) +(prefix) -(prefix) right to left* / % left to right+ - left to right= += -= right to leftOperators on the top line have

    13、the highest precedence.Precedence decreases line-by-line going down the table.All operators on the same line have equal precedence.,Assignment Operators,C treats = as an operator. Its precedence is lower than almost all of the other operators. Its associativity is right to left.,Form of an Assignmen

    14、t Expression,A simple assignment expression is of the form variable = right_side The value of right_side is assigned to variable, and that becomes the value of the assignment expression as a whole.,Assignment Expressions versus Assignment Statements,An assignment expression has no semicolon at the e

    15、nd. An assignment statement does. We can use assignment expressions to condense a sequence of assignment statements.,Example of Equivalent Code Using Assignment Expressions,Assignment statementsb = 2;c = 3;a = b + c; Equivalent statement using assignment expressionsa = (b = 2) + (c = 3); Note the as

    16、signment statement ends with a semicolon, the expressions dont.,Other Assignment Operators,C has operators that combine assignment with other operations. These are considered assignment operators and have the same precedence and right-to-left associativity as =. Example k = k + 2; is equivalent to k

    17、 += 2;,The Assignment Operators,= += -= *= /= %= = = &= = |= The semantics of the other assignment operators is specified byvariable op= expressionwhich is equivalent tovariable = variable op (expression)j *= k + 3 is equivalent to j = j * (k + 3)and notj = j * k + 3,Preprocessor Directives,Include

    18、files (header files) #include Causes the preprocessor to look for filename in system defined places and replace the #include line with a copy of contents of filename. #include “filename” Same as above, but the preprocessor looks in the current directory before looking in the system defined directory

    19、 locations.,Where are these “System Defined” Places?,On UNIX systems, the standard header files such as stdio.h can typically be found in the directory /usr/include. You can use any editor to look at what is in these files.,Header Files Must be Included for Functions in the Standard Library,The syst

    20、em knows where to find the code for functions in the standard library. However, it is the responsibility of the programmer to include the header files that provide the prototypes for library functions.,The Libraries versus the Header Files,The standard library contains object code (already compiled

    21、library functions). The standard header files are text files that you can read using a text editor. They provide information needed by the library functions.,Style,Do not condense code just for the sake of using less spacey = 2;z = 3;x = y + z; is more readable thanx = (y = 2) + (z = 3); anda += 7;

    22、versus a = a + 7; is a matter of choice.,Common Programming Errors,Warning and Error Messages usually refer to a line number. The problem may be prior to that line - such as not properly closing a comment or a string constant.,System Considerations,ANSI C has both a unary + and a unary - Traditional C has only unary -, so you should not use the unary + operator if your are writing code that needs to be portable to a machine that uses traditional C. If you are writing code for a spectrum of systems, limitations of all of the systems must be respected.,


    注意事项

    本文(C Programming.ppt)为本站会员(李朗)主动上传,麦多课文档分享仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文档分享(点击联系客服),我们立即给予删除!




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1 

    收起
    展开