最近學習C++,以便參加技能鑑定考試--學習CPP指針的用法

//指針的使用方法。

//遍歷數組的每個元素

#include "stdafx.h"

#include "iostream"

using namespace std;

int main()
{
//定義一個double類型的數組
double balance[10] = {100.3,1201.2,11.2,22.0,4.323,98.433,332.55,23.443,9845.34,0.8832};
//定義一個指針
double *p;
p = balance;
//輸出數組每個元素的值
cout << "使用指針的數組值:" << endl;
for (int i = 0;i<10;i++) {
cout << "*(p+" << i << "):";
cout << *(p + i) << endl;
}
cout << "使用balance作爲地址的數組值" << endl;
for (int i = 0;i<10;i++) {
cout << "*(balance+" << i << "):";
cout << *(balance+i) << endl;
}
return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章