//////////////////////////////////////////// // pointers.cpp - how do I use pointers? // //////////////////////////////////////////// #include using namespace std; void main() { double x; double *pD1 = &x; // pD1 holds the address of x *pD1 = 2.5; // contents of that address // is given a value cout << "\n x = " << x << ", *pD1 = " << *pD1 << '\n'; double *pD2 = new double[3]; // memory is allocated on heap *pD2 = 0.5; // memory is filled with values *(pD2+1) = 1.5; // using pointer arithmetic *(pD2+2) = 2.5; cout << "\n pD2[0] = " << pD2[0] // values are read out of memory << "\n pD2[1] = " << pD2[1] // using array notation << "\n pD2[2] = " << pD2[2] << "\n\n"; }