/******************************************************************* C201 Computer Programming II Fall 2006 Dana Vrajitoru & A program exercising pointers and dynamic memory allocation. ********************************************************************/ #include using namespace std; // Prototypes void Output(int *p); void Increment(int *p); void Find_largest_factor(int *p, int *q); int main() { int *n, *m, *p; // For the student: // Allocate the memory dynamically for n and m. // Initialize p to null. *n = 23; Increment(n); cout << "Information about n:" << endl; Output(n); Find_largest_factor(n, m); cout << endl << "Information about n:" << endl; Output(n); cout << "Information about m:" << endl; Output(m); // For the student: // Swap the addresses referenced by the two pointers n and m using // the additional pointer p. Do not swap their values. cout << endl << "Information about n:" << endl; Output(n); cout << "Information about m:" << endl; Output(m); // For the student: // Deallocate the memory for the pointers n and m. // Reinitialize all the pointers to null. return 0; } // Output the address stored in a pointer and the data stored at that // address. void Output(int *p) { cout << "The pointer contains the address " << p << endl << "At the address is stored the value " << *p << endl; } // Incrementing the value referenced by the pointer by one. void Increment(int *p) { (*p)++; } // Given two pointers p and q, the function assigns to the memory // location referenced by the second pointer the largest non-trivial // factor of the data referenced by p, meaning the largest factor not // equal to the number itself. For example, the largest non-trivial // factor of 50 is 25. void Find_largest_factor(int *p, int *q) { // To be completed by the student. }