c++ 04 数组和指针

数组、指针、动态数组

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

#include <string>
#include <bitset>

using std::cin;
using std::cout;
using std::endl;
using std::string;

int ()
{

const unsigned size = 3;
int ia[size] = { 0,1,2 };
// 使用下标遍历
for (size_t ix = 0; ix != size; ++ix)
cout << ix << ":" << ia[ix] << endl;
// 使用指针遍历
for (int *p = ia; p < ia + size; p++)
cout << p << ":" << *p << endl;
// 创建动态数组
int *pia = new int[10]; // array of 10 uninitialized ints
int *pia2 = new int[10](); //数组初始化 0
delete[] pia; // 动态空间释放
delete[] pia2;
return 0;
}

还有const、C字符串、二维数组。没啥好记的,用到时再来翻看。