zoukankan
html css js c++ java
C++:const sizeof 及array的学习笔记
#include
<
iostream
>
#include
<
stdlib.h
>
using
namespace
std;
/**/
/////////////////////////////////////////////////////////
//
void
TestPointArray();
/**/
/////////////////////////////////////////////////////////
/
void
TestConstRef()
{
int
a
=
100
;
const
int
&
b
=
a;
cout
<<
b
<<
endl;
//
100
a
=
2
;
cout
<<
b
<<
endl;
//
2
//
b = 1;
//
error
const
int
&
c
=
300
;
cout
<<
c
<<
endl;
}
void
TestSizeof()
{
char
s1[
6
]
=
"
ABCDE
"
;
char
*
s2
=
"
abcde
"
;
char
s3[]
=
"
abcde
"
;
cout
<<
sizeof
(s1)
<<
endl;
//
6
cout
<<
sizeof
(s2)
<<
endl;
//
4
cout
<<
sizeof
(s3)
<<
endl;
//
6
}
void
TestArray()
{
int
a[]
=
{
1
,
2
,
3
,
4
,
5
}
;
int
*
p
=
a;
cout
<<
p
<<
endl;
//
0x22ff50
cout
<<*
p
++<<
endl;
cout
<<
p
<<
endl;
//
?
cout
<<
p
-
a
<<
endl;
//
?
cout
<<*++
p
<<
endl;
//
3
cout
<<*
(p
+
1
)
<<
endl;
cout
<<*
((
int
*
)((
char
*
)p
+
1
))
<<
endl;
//
哈哈, 是 0x4000
}
void
TestArrPara(
int
a[
5
])
{
cout
<<
*
(a
++
)
<<
endl;
//
OK
}
int
main(
int
argc,
char
*
argv[])
{
//
TestConstRef();
//
TestSizeof();
//
TestArray();
int
a[]
=
{
1
,
2
,
3
,
4
,
5
}
;
//
TestArrPara(a);
TestPointArray();
system(
"
PAUSE
"
);
return
0
;
}
void
TestPointArray()
{
int
a[]
=
{
1
,
2
,
3
,
4
,
5
}
;
int
(
*
p)[
5
];
p
=
&
a;
cout
<<*
p[
0
]
<<
endl;
cout
<<*
p[
1
]
<<
endl;
cout
<<*
p[
2
]
<<
endl;
cout
<<*
p[
3
]
<<
endl;
cout
<<*
p[
4
]
<<
endl;
cout
<<
endl;
cout
<<
(
*
p)[
0
]
<<
endl;
cout
<<
(
*
p)[
1
]
<<
endl;
cout
<<
(
*
p)[
2
]
<<
endl;
cout
<<
(
*
p)[
3
]
<<
endl;
cout
<<
(
*
p)[
4
]
<<
endl;
cout
<<
endl;
cout
<<
p[
0
]
<<
endl;
cout
<<
p[
1
]
<<
endl;
cout
<<
p[
2
]
<<
endl;
cout
<<
p[
3
]
<<
endl;
cout
<<
p[
4
]
<<
endl;
cout
<<
endl;
cout
<<
a
+
0
<<
endl;
cout
<<
a
+
1
<<
endl;
cout
<<
a
+
2
<<
endl;
cout
<<
a
+
3
<<
endl;
cout
<<
a
+
4
<<
endl;
cout
<<
endl;
int
*
q
=
*
p;
cout
<<
*++
q
<<
endl;
}
查看全文
相关阅读:
POJ1611 && POJ2524 并查集入门
POJ 2785:4 Values whose Sum is 0 二分
POJ 2309:BST lowbit
POJ 3692:Kindergarten 求补图的最大点独立集 头一次接触这样的做法
POJ 3735:Training little cats 联想到矩阵相乘
POJ 3916:Duplicate Removal 将相近的重复元素删除
nyoj43--24 Point game(dfs)
cf-Igor In the Museum (dfs)
8VC Venture Cup 2016 -- Elimination Round Tutorial 626B
蓝桥杯
原文地址:https://www.cnblogs.com/qkhh/p/1038938.html
最新文章
吃货联盟
《Oracle数据库》Oracle 常见用法
《Java Spring框架》Idea+gradle 整合Springboot和Mybatis
《Java Spring框架》通过Idea 整合Spring和Mybatis
《Java Spring框架》Spring事务管理
《Java算法》Java动态规划
《Java Spring框架》Spring Http发送和接收案例
《MySQL数据库》MySQL my.conf配置详解
《MySQL数据库》MySQL用户赋权
《番外篇》Xshell和Xftp安装教程
热门文章
《Java算法》Java回溯算法
友情提醒:欲开发android5.0以上应用,请全部更新开发工具至最新
android sdk 个版本下载
细说ASP.NET Forms身份认证
android开发环境搭建
从零开始学android开发
POJ 3321:Apple Tree 树状数组
POJ 1151:Atlantis 线段树+扫描线
POJ1703 && POJ2942 &&POJ 1182 并查集 这个做法挺巧妙
POJ 1905:Expanding Rods 求函数的二分
Copyright © 2011-2022 走看看