I am using a pointer to a double as an argument for a function that prints out the memory address, contents and name of the variable that the pointer points to, but I can't figure out how to output the name of the variable that the pointer points to.
Here is the code:
Code:#include <iostream> #include <string.h> void iaddress(double* num); int main() { double num1 = 1.23; double num2 = 100.75; char *str1 = new char[26]; strcpy(str1, "Pointers are interesting!"); double num3 = -35.5; double *ptr4 = new double; int i = 0; // str1 output cout << "str1 - main: address: " << &str1 << " contents: " << str1 << endl; // num1 output and function call cout << "num1 - main: address: " << &num1 << " contents: " << num1 << endl; ptr4 = &num1; iaddress(ptr4); // num2 output and function call cout << "num2 - main: address: " << &num2 << " contents: " << num2 << endl; ptr4 = &num2; iaddress(ptr4); // num3 output and function call cout << "num3 - main: address: " << &num3 << " contents: " << num3 << endl; ptr4 = &num3; iaddress(ptr4); // ptr4 output and function call cout << "ptr4 - main: address: " << ptr4 << " contents: " << *ptr4 << endl; *ptr4 = 123.4; iaddress(ptr4); delete ptr4; delete [] str1; return 0; } // FUNCTION HEADER AND CODE void iaddress(double* num) { cout << " " << num << "- main: address: " << num << " contents: " << num << endl; delete num; }
Thanks for any help.
Brian