河南工业大学信息科学与工程学院程序设计基础课件 Lecture15.pptVIP

  • 1
  • 0
  • 约3.96千字
  • 约 22页
  • 2019-05-10 发布于广东
  • 举报

河南工业大学信息科学与工程学院程序设计基础课件 Lecture15.ppt

Check it out If pointer is a kind of data type of unsigned int, then (1) Is its size the same big as an integer in memory? (指针在内存中的大小和整型一样大吗?) (2) Can pointer variables do add and/or subtraction? operation? (指针能做加减法吗?) * 指针的数据是unsigned int Let’s check it! * Let’s check it again! * 200kg的大胖子和50kg的小瘦子,它们的身份证都是18位! Thanks for your attention! * Yuhong Zhang (张玉宏) yhzhang@haut.edu.cn Henan University of Technology * * * * * * 此处添加公司信息 LOGO 此处添加公司信息 此处添加公司信息 此处添加公司信息 此处添加公司信息 此处添加信息 此处添加公司信息 此处添加公司信息 Lecture15 指针(1) 《程序设计基础》课程组 制 Part 1: Definition of Pointer 8.1 Introduction Pointers Powerful, but difficult to master Simulate call-by-reference (注:C++中传引用的概念) Close relationship with arrays and strings * Memory Concepts(内存的概念) Variables Variable names correspond to locations in the computers memory Every variable has a name, a type, a size and a value Reading variables from memory does not change them A visual representation int x = 45; 1101 0010 0000 0000 X 0000 0001 0002 0003 每个字节(8个bit)分配一个内存编号(地址) sizeof(x) = 4 * 指针就是在内存中一块数据的起始地址 int x ; x Pointer * 使用指针的原因是? 传递数据方便 * 使用指针的原因是? 不同程序可以在相同的地址空间干活 8.2 Pointer Variable Declarations and Initialization (指针变量的声明与初始化) Pointer variables Contain memory addresses as their values Normal variables contain a specific value (direct reference) Pointers contain address of a variable that has a specific value (indirect reference) Indirection – referencing a pointer value ? count 2.5 count 2.5 countPtr Address of count in memory 指针的定义 指针是用来存储其它数据的地址的特殊整型变量。 指针的定义有两种写法: 指针变量类型* 指针变量名称; 指针变量类型 *指针变量名称; 如:float* countPtr; // recommend float *countPtr; //old version * 知识回顾:特殊的整型——指针(pointer) 指针(pointer):它是一个无符号的整型数! 所有的数据都必须在内存中才能处理,每个数据在内存中都有下列四个相关的特性: 1.数据名称; 2.数据类型,用来规范该数据的存储方 式和占用的内存大小; 3.数据内容; 4.该数据所在内存的地址。 * 指针的定义(续) 假设有以下语句: float count = 2.5; float* countPtr; //定义指针pF

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档