Array passed by pointer - C++ Data Type

C++ examples for Data Type:Array

Description

Array passed by pointer

Demo Code

#include <iostream>
using namespace std;
const int MAX = 5;           //number of array elements
int main()//from  ww  w  .  jav a  2 s .  co m
{
   void centimize(double*);  //prototype
   double varray[MAX] = { 10.0, 43.1, 95.9, 59.7, 87.3 };
   centimize(varray);        //change elements of varray to cm
   for(int j=0; j<MAX; j++)  //display new array values
      cout << "varray[" << j << "]=" << varray[j] << " centimeters" << endl;
   return 0;
}
void centimize(double* ptrd)
{
   for(int j=0; j<MAX; j++)
      *ptrd++ *= 2.54;       //ptrd points to elements of varray
}

Result


Related Tutorials