- 2
- 0
- 约 97页
- 2017-04-28 发布于四川
- 举报
第二章数据类型运算符和表达式[完整]
第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
您可能关注的文档
最近下载
- 2025年单招政治试题及答案.docx VIP
- 康复治疗师师物理因子治疗试题及详解.doc VIP
- 2025年包头钢铁职业技术学院单招职业技能测试题库(历年真题).docx
- cadence allegro 17.4设计入门教程.pdf VIP
- 2025年包头钢铁职业技术学院单招职业适应性测试题库(各地真题).docx VIP
- 2025年中药学专升本考试真题卷(附每题答案).pdf VIP
- 2026年采购招标采购谈判技巧培训课件.pptx
- 2025年烟草企业-烟草招聘-综合题库历年参考题库含答案解析(5套).docx VIP
- 工程电磁场跟电磁波答案(丁君).pdf VIP
- 无人驾驶技术原理及应用 课件 11.3无人农牧业 .pptx
原创力文档

文档评论(0)