#include <iostream>
#include <vector>
using namespace std;
int main ()
{
int v1[] = {1,8,45,100,200}; // v1 是一个数组,
int *xiao = v1; // 指针可以定义一个数组,
cout << *xiao << endl;
xiao = &v1[0]; // 等于xiao = v1[0] 只能是表示第一个数的时候可以相等,
int *xiao2 = v1 + 4;
cout << *xiao << endl;
ptrdiff_t j = xiao2 - xiao; // 这是指针的减法应用,
cout << j << endl; //输出是4,
int two = *xiao2; //*引用要用括号,等于int two = *(v1 + 4)
cout << two << endl; // 输出的是数组的最后一个数200,
int *k = &v1[1];
cout << *k << endl; // 输出是8,指向第二个数
int q = k[1];
cout << q << endl; // 输出是45,指向第三个数,
const size_t x_c = 5;
int y_c[x_c] = {1,2,3,4,5};
for(int *pbegin = y_c, *pend = y_c + x_c;
pbegin != pend;
++pbegin)
cout << *pbegin << endl; //指针循环数组,
vector<double> ivec;
ivec.push_back(0.1);
ivec.push_back(0.2);
ivec.push_back(0.3);
ivec.push_back(0.4);
for(vector<double>::iterator iter = ivec.begin();
iter != ivec.end();
++iter)
cout << *iter << endl; // 指针循环数组,
return 0;
}