第二章数据类型运算符和表达式[完整].ppt

第二章数据类型运算符和表达式[完整].ppt

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

第2章 数据类型、运算符与表达式;本章学习内容;C Program Structure;例2.1:一个简单的C程序例子 ;C程序常见符号分类 ;C程序常见符号分类 ;标识符命名 ;何谓变量(Variable )?;如何衡量变量所占空间大小?;一个位有多大? 只能是“0”或者“1”,二进制 一个字节有多大? 可以表示数字0~255之间的整数 保存一个字符(英文字母、数字、符号) ASCII(美国标准信息交换码)编码(附录A);Needs to be declared: 变量类型 变量名;;变量声明(Variable Declaration);Example: int number1, number2; number1 = 25; number2 = 23; number1 = number2; … … ;Algorithm 变量 ? 表达式 Syntax 变量 = 表达式 ; Rules:类型一致 Expression’s type must be the same as variable’s type ;Example: Calculate and display the price of a number of apples if the quantity in kg and price per kg are given. Input: quantity and pricePerkg Output: price Process: price = quantity * pricePerkg ;Example: int quantity; float pricePerkg, price; quantity = 5; pricePerkg = 4.50; price = quantity * pricePerkg; …;Example: int quantity; float pricePerkg, price; quantity = 2; pricePerkg = 4.50; price = quantity * pricePerkg; …;Example: int quantity; float pricePerkg; float price; ;数据类型(Data Type);数据类型(Data Type);基本数据类型;数据类型修饰符;不同类型取值范围不同;整型类型的取值范围;浮点类型的取值范围;不同类型取值范围不同;何谓类型溢出(Overflow)?;解决方案?;不同类型占用的内存字节数不同;sizeof到底是什么?;现场演示例2.3 在TC和VC的运行结果;不同类型数据 在内存中的存储形式不同 ;常量(Constant);字符常量;字符常量;例2.5:小写字母转换为大写字母 ;字符串常量;宏常量;例2.2 :计算圆的周长和面积 ;例2.2 :计算圆的周长和面积 ;为什么需要常量?;运算符( Operator );运算符和操作数 (Operator and Operand);表达式 Expression;算术运算符(Arithmetic Operators);Multiplication(*), addition(+) and subtraction(-) are the simplest to use Division(/) is easy, but some precautions need to be taken Modulus(%) is the one that normally confuses novices So, let’s study in detail the Division and Modulus ;除法(Division);Example: ;Example: ;Example: ;;求余(Modulus);Example: ;;Example: ;Example: ;Example: ;An expression may contain 2 or more arithmetic operators Main issue: 运算顺序 ORDER OF PRECEDENCE 优先级;Examples: ;;Example: ;巧妙使用圆括号改变运算顺序 All expressions in parentheses must be evaluated prior to values outside brackets Nested parenthesized expressions must be evaluated from the inside

文档评论(0)

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

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

1亿VIP精品文档

相关文档