程序的设计基础w07-讨论4-数组-指针-函数.ppt

程序的设计基础w07-讨论4-数组-指针-函数.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
排错涉及到一种逆向推理,就像侦破一个杀人谜案。有些不可能的事情发生了,而仅有的信息就是它确实发生了!因此,我们必须从结果出发,逆向思考,去发现原因。 有时你“看到的代码”实际上是你自己的意愿,而不是你实际写出来的东西。离开它一小段时间能够松驰你的误解,帮助代码显出其本来面目。 ———— 《程序设计实践》;关于数组、指针、函数 的综合讨论;*;*;*;*;*;*;*;*;*;*;*;*;*;*;*;*;;*;*;*;*;*;*;*;*;*;*;*;*;*;*;*;*;*;*;*;*;*;*;*;*;*;*;*;*;;*;;*;*;*;*;*;*;(未完持续……);数组与指针;参考输???;请在此页总结要点;;参考输出;请在此页总结要点;;int main() { int a1[4] = {1,2,3}; int a2[5] = {1,2,1,2,9}; cout main(): a1 = a1 , a2 = a2 endl; test_1(a1, 4); test_1(a2, 5); test_2(a1, 4); test_2(a2, 5); int* p = a2; test_1(p, 2); test_2(p, 3); return 0; } // pointer-array-3.cpp;参考输出;请在此页总结要点;数组与指针;数组与指针;参考输出;请在此页总结要点;数组与指针;数组与指针;参考输出;请在此页总结要点;void test_7(int a[3][4]) // 两个维度都是固定的 二维数组 { int len1 = 3, len2 = 4; for (int i=0; ilen1; i++) { for (int j=0; jlen2; j++) { cout a[i][j] ; } cout endl; } } void test_8(int a[][4], int len) // 第二维固定的 二维数组 { int len1 = len, len2 = 4; for (int i=0; ilen1; i++) { for (int j=0; jlen2; j++) { cout a[i][j] ; } cout endl; } };void test_9(int* a[4], int len) { int len1 = len, len2 = 4; for (int i=0; ilen1; i++) { for (int j=0; jlen2; j++) cout a[i][j] ; cout endl; } } #ifdef SHOW_ERROR void test_10(int a[][], int len1, int len2) { for (int i=0; ilen1; i++) { for (int j=0; jlen2; j++) cout a[i][j] ; cout endl; } } #endif void test_11(int** a, int len1, int len2) { for (int i=0; ilen1; i++) { for (int j=0; jlen2; j++) cout a[i][j] ; cout endl; } };int main() { int b[3][4] = {{1,1,1,81}, {2,2,2,72}, {3,3,3,63}}; int c[4][3] = {{1,2,3}, {4,5,6}, {7,8,9}, {9,8,7}}; cout call test_7() to output matrix b: endl; test_7(b); // test_7(int a[3][4]) cout call test_8() to output matrix b: endl; test_8(b, 3); // test_8(int a[][4], int len) #ifdef SHOW_ERROR test_7(c); test_8(c, 4); test_9(b, 3); test_10(b, 3, 4); // test_10(int a[][], int, int) test_11(b, 3, 4); // test_11(int**, int, int) test_11((int*)(b), 3, 4); // 强制转换也不行! test_11

文档评论(0)

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

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

1亿VIP精品文档

相关文档