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

  • 2
  • 0
  • 约 97页
  • 2017-04-28 发布于四川
  • 举报

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

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

第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)

1亿VIP精品文档

相关文档