// Ex742.cc // Sec. 7.4 of lecture // Pointer as OUTPUT parameter #include // n and xp are OUTPUT parameters //void Allocate(int n, double* xp); // VERY WRONG //void Allocate(int & n, double* xp); // WRONG void Allocate(int & n, double* & xp); // RIGHT main() { int length=0; double *pp = 0; // initialize pointer with NULL Allocate(length, pp); cout << "I allocated " << length << " double numbers"; cout << " at address " << pp << endl; delete [] pp; } //void Allocate(int n, double* xp); // VERY WRONG //void Allocate(int & n, double* xp) // WRONG void Allocate(int & n, double* & xp) // RIGHT { cout << " Length of array : "; cin >> n; xp = new double [n]; return; }