C++数组字符串指针.ppt

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

* * * * * * * * 例8-20(例6-15) 通过指针访问类的静态函数成员 * #include iostream using namespace std; class Point { //Point类定义 public: //外部接口 Point(int x = 0, int y = 0) : x(x), y(y) { count++; } Point(const Point p) : x(p.x), y(p.y) { count++; } ~Point() { count--; } int getX() const { return x; } int getY() const { return y; } static void showCount() { cout Object count = count endl; } private: //私有数据成员 int x, y; static int count; }; int Point::count = 0; 8.3 指针 —— 8.3.11 对象指针 例8-20 (续) * int main() { //主函数实现 //定义一个指向函数的指针,指向类的静态成员函数 void (*funcPtr)() = Point::showCount; Point a(4, 5); //定义对象A cout Point A: a.getX() , a.getY(); funcPtr(); //输出对象个数,直接通过指针访问静态函数成员 Point b(a); //定义对象B cout Point B: b.getX() , b.getY(); funcPtr(); //输出对象个数,直接通过指针访问静态函数成员 return 0; } 8.3 指针 —— 8.3.11 对象指针 小结 * 8.4 小结 主要内容 数组、字符串、指针 达到的目标 理解数组、指针的概念,掌握定义和使用方法,会使用string类。 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 例8-10 (续) 使用指针变量 * 6.2 指针 —— 6.2.6 用指针处理数组元素 #include iostream using namespace std; int main() { int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; for (int *p = a; p (a + 10); p++) cout *p ; cout endl; return 0; } 8.3.7 指针数组 数组的元素是指针型 例:Point *pa[2]; 由pa[0],pa[1]两个指针组成 * 8.3 指针 例8-11(教材例6-8) 利用指针数组存放单位矩阵 * 8.3 指针 —— 8.3.7 指针数组 #include iostream using namespace std; int main() { int line1[] = { 1, 0, 0 }; //矩阵的第一行 int line2[] = { 0, 1, 0 }; //矩阵的第二行 int line3[] = { 0, 0, 1 }; //矩阵的第三行 //定义整型指针数组并初始化 int *pLine[3] = { line1, line2, line3 }; 例8-11(续) * 8.3 指针 —— 8.3.7 指针数组 cout Matrix test: endl; //输出单位矩阵 for (int i = 0; i 3; i++) { for (int j = 0; j 3; j++) cout pLine[i][j] ; cout endl; } return 0; } 输出结果为: Matrix test: 1,0,0 0,1,0 0,0,1 例8-12(教材例6-9) 二维数组举例 * 8.3 指针 —— 8.3.7 指针数组 #include iostream using namespace std; int main() { int array2[3][3]= { { 11, 12, 13 }, { 21, 22, 23 }, { 31, 32, 33 } }; for(int i = 0; i 3; i++) { for(int j = 0; j 3; j++) cou

文档评论(0)

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

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

版权声明书
用户编号:6111134150000003

1亿VIP精品文档

相关文档