cout<<"Please enter a number that you want to square\n";
cin>>n;
cout<<"The number you entered is "<<n;
cout<<"\nThe twice of "<<n<< " is "<<add(n);
cout<<"\n";
cout<<"The refference memory adress of this number is..........";
cout<<f(n)<<"\n";// Please explain what this program is doing here. and what is this code.
// the program compiles but I have not understood how this code works
Well this is some deep question you should probably read more about than just my explanation.
However:
When you createa a variable: double u; then there is a field created in your memory (RAM) that is big enough to hold a number of type "double".
when you now write cout << &u;
it shows you in "hexadecimal" (another representation of binary (to the base 16): shorter and easier to read) the exact location of your field inside the memory (RAM). (more precise the address of the first byte of your "double"-field (which is actually 8 byte large).