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;
}
查看全文
相关阅读:
021-python基础-python介绍及课程简介
020-python函数和常用模块-文件操作
019-python函数和常用模块-内置函数
018-python基础-三元运算和lambda表达式
017-python函数和常用模块-函数式编程实现登陆和注册
016-python函数和常用模块-函数定义和使用
015-python基础-深浅拷贝
014-python基础-set集合
013-python基础-课堂练习
012-python基础-数据运算
原文地址:https://www.cnblogs.com/qkhh/p/1038938.html
最新文章
通过ffi在node.js中调用动态链接库[转]
javaScript Event Loop + NodeJs问题解析
手机touch事件及参数【转】(自己懒得写了,找了一篇摘过来)
[ActiveRecord] 之 实体映射
[ActiveRecord]之 CRUD
[ActiveRecord] 之多数据库配置
[ActiveRecord] 之ActiveRecordMediator
[ActiveRecord] 之Cascade
控件属性、事件持久化(转)
未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项。试图加载格式不正确的程序。
热门文章
嵌套字典和游戏物品清单
文件的读写过程open read write close
Python模块之-OS模块
正则RE
python打印表格式数据,留出正确的空格和段落星号或注释
统计一个字符串中每个字符出现的次数和井字棋盘游戏
逗号代码和字符图网络
Python3:Collatz 序列(考拉咨猜想)
psdash-为开发、测试人员提供简单的方法,在web界面查看服务器的运行情况(网络,带宽,磁盘,CPU), 同时可以在web界面查看日志
python build-in function
Copyright © 2011-2022 走看看