int*p[ ]与int(*p)[ ]的不同
举例说明:
1)int* p[2] 是一个指向int型的指针数组,即:p是包含两个元素的指针数组,指针指向的是int型。
可以这样来用:
#include <iostream> using namespace std; int main(int argc, char* argv[]) { int* p[2]; int a[3] = {1, 2, 3}; int b[4] = {4, 5, 6, 7}; p[0] = a; p[1] = b; for(int i = 0; i < 3; i++) cout << *p[0] + i;// cout << **p + i; cout << endl; for(i = 0; i < 4; i++) cout << *p[1] + i;// cout << **p + i; return 0; }
(2)对于 int (*p)[2], 它相当于一个二维数组的用法,只是它是一个n行2列的数组,可以这样来用:
#include <iostream> using namespace std; void main() { int (*p)[2]; int b[3][2] = {{1, 2}, {3, 4}, {5, 6}}; p = b; for(int i = 0; i < 3; i++) { for(int j = 0; j < 2; j++) //cout << p[i][j]; //cout << *(*(p+i)+j); cout << endl; } }
注意:
(1)为行数确定、列数不确定,即为2*n型的。
(2)为n*2型的数组的指针用法,即行数不确定、列数确定。
对于(1)其等价形式如下:
#include <iostream> using namespace std; void main() { int** array; array = new int* [2]; int a[3] = {1, 2, 3}; int b[4] = {4, 5, 6, 7}; array[0] = a; // *array = a; array[1] = b; // *(array+1) = b; for(int i = 0; i < 3; i++) cout << array[0][i];// cout << *array[0] + i; cout << endl; for(int j = 0; j < 4; j++) cout << array[1][j];// cout << *array[1] + j; }
其实以上用法即这我们常用的动态二维数组的用法。
int*p[ ]与int(*p)[ ]的不同的更多相关文章
- Convert.ToInt32()、int.Parse()和(int)三者的区别
Convert.ToInt32将object类类型转换成int类型,如Convert.ToInt32(session["shuzi"]); (int)适合简单数据类型之间的转换: ...
- 深度解析C语言int与unsigned int
就如同int a:一样,int 也能被其它的修饰符修饰.除void类型外,基本数据类型之前都可以加各种类型修饰符,类型修饰符有如下四种:1.signed----有符号,可修饰char.int.Int是 ...
- C#中(int)、int.Parse()、int.TryParse()和Convert.ToInt32()的区别
转自:http://www.cnblogs.com/leolis/p/3968943.html 在编程过程中,数据转换是经常要用到的,C#中数据转换的方法很多,拿将目标对象转换为 整型(int)来讲, ...
- what is difference in (int)a,(int&)a,&a,int(&a) ?
This interview question come from a famous communication firm of china. : ) #include <iostream> ...
- int(3)和int(10)的区别
int(M) 在 integer 数据类型中,M 表示最大显示宽度.在 int(M) 中,M 的值跟 int(M) 所占多少存储空间并无任何关系. int(3).int(4).int(8) 在磁盘上都 ...
- C#中(int)、int.Parse()、int.TryParse()和Convert.ToInt32()的区别 <转>
作者:Statmoon 出处:http://leolis.cnblogs.com/ 在编程过程中,数据转换是经常要用到的,C#中数据转换的方法很多,拿将目标对象转换为整型(int)来讲,有四种方法 ...
- 【C】二级指针探秘 & 星号的两种用法(1.与基本类型结合形成另一种类型,比如与int结合形成int* 2.取值操作)
1)问题:二级指针到底是什么?怎么用的?怎么存放的? #include <stdio.h> #define TEST_ADDR 0x12FF40 void main() { int a = ...
- int.Parse()、int.TryParse()和Convert.ToInt32()的区别
1:int.Parse(一个参数) 此参数必须满足: 1 只能是字符串: 2 只能是 “整型” 字符串,即各种整型ToString()之后的形式,也不能为浮点型. 2:int.TryPa ...
- (int)、int.Parse()、int.TryParse()和Convert.ToInt32()的区别
C#中(int).int.Parse().int.TryParse()和Convert.ToInt32()的区别 原文链接:http://www.cnblogs.com/leolis/p/3968 ...
- Java-集合-第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; 其中,classNum 表示学生的班号,例如“class05”。 有如下List List list = new ArrayList(); l
第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; ...
随机推荐
- 3.1 One-dim Vector Initialtization
vector<int> v(10, -1); //10个-1 v.size(); v.empty(); //is empty?
- git reset揭秘
一.命令 首先,让我们来解释几个定义. HEAD(头) 指向当前branch最顶端的一个commit,该分支上一次commit后的节点 Index(索引) The index, ...
- linux系统性能监控--CPU利用率
在对系统的方法化分析中,首要且最基本的工具之一常常是对系统的 CPU利用率进行简单测量. Linux以及大多数基于 UNIX的操作系统都提供了一条命令来显示系统的平均负荷(loadaverage) . ...
- 大规模WebGL应用引发浏览器崩溃的几种情况及解决办法
一般的Web应用基本上不会导致浏览器崩溃,写Javascript代码也不需要管理内存资源,基本也不需要考虑内存"泄露"的问题.随着H5的崛起,越来越多的原本在桌面端的软件也改头换面 ...
- Gradle 1.12用户指南翻译——第四十五章. 应用程序插件
本文由CSDN博客貌似掉线翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...
- CDH集群安装&测试总结
0.绪论 之前完全没有接触过大数据相关的东西,都是书上啊,媒体上各种吹嘘啊,我对大数据,集群啊,分布式计算等等概念真是高山仰止,充满了仰望之情,觉得这些东西是这样的: 当我搭建的过程中,发现这些东西是 ...
- RxJava操作符(09-算术/聚合操作&连接操作)
转载请标明出处: http://blog.csdn.net/xmxkf/article/details/51692493 本文出自:[openXu的博客] 目录: 算术聚合 Count Concat ...
- HDFS基本原理及数据存取实战
---------------------------------------------------------------------------------------------------- ...
- Latex 文本编辑技巧
临时取消首行缩进 \noindent 生成随机文本 \usepackage{lipsum} \begin{document} \lipsum \end{document} 多栏模式 \usepacka ...
- 剑指Offer——完美+今日头条笔试题+知识点总结
剑指Offer--完美+今日头条笔试题+知识点总结 情景回顾 时间:2016.9.28 16:00-18:00 19:00-21:00 地点:山东省网络环境智能计算技术重点实验室 事件:完美世界笔试 ...