![](smile.gif)
![](smile.gif)
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
//object creationsMyClass Object;MyClass *PointerToObject;//parameter definitionvoid function( MyClass &ReferenceToObject);void function2( MyClass *PtrToObject );
main(){ function( *PointerToObject ); function( Object ); function2( &Object ); function2( PointerToObject );}
#include<iostream> // For coutusing namespace std; // Utilize the standard key words.void createDynammicMemory(double*&, float*&); //used to create two pointersvoid destroyDynammicMemory(double*, float*); //destroys the dynammic area that was pointed to.int main(){ double *doublePointer; //this is a local, automatic pointer to a place in memory that will hold a double float *floatPointer; //this is a local, automatic pointer to a place in memory that will hold a float createDynammicMemory(doublePointer, floatPointer); cout << "In main, after pointers have been initialized." << endl; cout << "The address of the pointer to the double = " << int(doublePointer) << endl; cout << "the value stored at the address = " << *doublePointer << endl; cout << "The address of the pointer to the float = " << int(floatPointer) << endl; cout << "the value stored at the address = " << *floatPointer << endl << endl; destroyDynammicMemory(doublePointer, floatPointer); cout << "In main, after pointers have been destroyed." << endl; cout << "The address of the pointer to the double = " << int(doublePointer) << endl; cout << "the value stored at the address = " << *doublePointer << endl; cout << "The address of the pointer to the float = " << int(floatPointer) << endl; cout << "the value stored at the address = " << *floatPointer << endl << endl; return 0;} // end of mainvoid createDynammicMemory(double*& dp, float*& fp)//pre: local pointers have been declared, and have been referenced into this function.//post: new memory will be dynamically allocated for the data types of the pointers passed into function, // and will be initialized.{ dp = new double(5.0); if(dp == NULL) // test to see if there is available memory space { cout << "Error! no space to allocate memory, program endidng! " << endl; exit(0); } // end if statement fp = new float(10.f); if(fp == NULL) // test to see if there is available memory space { cout << "Error! no space to allocate memory, program endidng! " << endl; exit(0); } // end if statement cout << "In createDynammicMemory, after pointers have been initialized." << endl; cout << "The address of the pointer to the double = " << int(dp) << endl; cout << "the value stored at the address = " << *dp << endl; cout << "The address of the pointer to the float = " << int(fp) << endl; cout << "the value stored at the address = " << *fp << endl << endl;}// end createDynammicMemoryvoid destroyDynammicMemory(double* p1, float* p2)//pre: pointers have been used, and are now passed by copy into this function//post: the memory used by pointers will be freed up{ delete p1; delete p2;} // end destroyDynammicMemory/*OUTPUTIn createDynammicMemory, after pointers have been initialized.The address of the pointer to the double = 8261296the value stored at the address = 5The address of the pointer to the float = 8261248the value stored at the address = 10In main, after pointers have been initialized.The address of the pointer to the double = 8261296the value stored at the address = 5The address of the pointer to the float = 8261248the value stored at the address = 10In main, after pointers have been destroyed.The address of the pointer to the double = 8261296the value stored at the address = -1.45682e+144The address of the pointer to the float = 8261248the value stored at the address = -1.9984e+018Press any key to continue*/