const int SIZE = 6;
const double payRates[SIZE] = { 18.55, 17.45, 12.85, 14.97, 10.35, 18.89 };
void displayPayRates(const double *rates, int size) { // Set numeric output formatting cout << setprecision(2) << fixed << showpoint; // Display all the pay rates for (int count = 0; count < size; count++) { cout << "Pay rate for employee " << (count + 1)<< "is $" << *(rates + count) << endl; } }在函數頭中,請注意 rates 形參被定義為一個指向 const double 的指標。應該指出的是,const 這個單詞適用於 rates 指向的東西,而不是 rates 本身,如圖 1 所示。