// chapter09a05指针的运算.cpp
//
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
//指针的算术运算符 ( ++ --)
int i;
double score[] = { 75,86,84,90 };
double* ptr_score;
ptr_score = score;
for (int i = 0; i < 4; i++)
{
cout << *ptr_score++ << '\t';
}
cout << endl;
//75 86 84 90
for (int i = 0; i < 4; i++)
{
cout << ptr_score++ << '\t';
}
//0042F9D0 0042F9D8 0042F9E0 0042F9E8
cout << endl;
cout << "!!" << endl;
//指针的算术运算符 ( + -)
int i2;
double score2[] = { 75,86,84,90 };
double* ptr_score2;
ptr_score2 = &score2[1]; //第二个元素的地址
ptr_score2 += 2;
cout << ptr_score << endl; //第四个元素的地址 00EFFCB8
ptr_score2 -= 3;
cout << ptr_score << endl; //第一个元素的地址 00EFFCB8
cout << endl;
}
VS2017学习C++基础九(指针的运算)
最新推荐文章于 2021-06-11 16:38:26 发布