C++实例---数组访问(指针)
2017-02-15 15:52
218 查看
代码:
运行结果:
#include <iostream> #include <iomanip> #include <string> using namespace std; int main (int argc, char **argv) { int a[3][3] = {1,2,3,4,5,6,7,8,9}; int i = 1, j = 1; int (*p)[3]; cout<<"i = "<<i<<", j = "<<j<<endl; for (int k = 0; k < 3; k ++) { for (int w = 0; w < 3; w ++) cout<<setw(5)<<a[k][w]; cout<<endl; } p = a; cout<<"*(*(a+i)+j) = "<<*(*(a+i)+j)<<endl; cout<<"*(a+i)[j] = "<<*(a+i)[j]<<endl; cout<<"*(a+3*i+j) = "<<*(a+3*i+j)<<endl; //overstep the boundary cout<<"*(*(p+i)+j) = "<<*(*(p+i)+j)<<endl; cout<<"*(p[i]+j) = "<<*(p[i]+j)<<endl; cout<<"*(p+i)[j] = "<<*(p+i)[j]<<endl; cout<<"*(p+3*i+j) = "<<*(p+3*i+j)<<endl; //overstep the boundary cout<<"p[i][j] = "<<p[i][j]<<endl; return 0; }
运行结果:
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- 关于指针的一些事情
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- ruby 数组使用教程
- Ruby中的数组和散列表的使用详解
- C#实现AddRange为数组添加多个元素的方法
- C#比较二个数组并找出相同或不同元素的方法
- 快速解决C# android base-64 字符数组的无效长度问题
- C#中数组、ArrayList和List三者的区别详解
- C# 拷贝数组的几种方法(总结)
- C#动态调整数组大小的方法
- Lua中调用C++函数示例
- 详解Lua中的数组概念知识
- Lua教程(一):在C++中嵌入Lua脚本
- Perl中的列表和数组学习笔记
- Lua教程(二):C++和Lua相互传递数据示例
- jQuery 判断是否包含在数组中Array[]的方法
- 浅谈C#各种数组直接的数据复制/转换