Lecture 5 Examples


image from book

Open table as spreadsheet

Program

Demonstrates

address.cpp

This program illustrates the use of the address operator.

arrayptr.cpp

This program illustrates the use of using a pointer to control an array.

byPointer.cpp

This program demonstrates passing by pointer a variable into a function thereby changing the value of a local variable.

date.cpp

This program seeks a date and tells what day of the week and month it is.

delete.cpp

Shows the use of pointers as output of functions. Note that the operator delete is used only once even though the new operator is used twice to create two different char arrays dynamically.

indirect.cpp

Show the use of the indirection operator.

menus.cpp

This program contains the menus for all modules of the accounting system. From these menus the user can select which of the accounting modules he/she wants to use.

nullptr.cpp

Shows the use of the NULL pointer.

pointerAddition.cpp

Shows pointers addition.

pointerconversion.cpp

Shows how to initialize a pointer of a different type. Shows that a pointer of one type may not work as a pointer to different type.

ptrinilz.cpp

Shows how to initialize a pointer.

ptrtofn.cpp

This program illustrates the use of function pointers.

relationalptr.cpp

This program illustrates the use of using a pointer with relational operators.

renewptr.cpp

This program demonstrates the use of the operators new and delete. It shows how pointers are defined to point to blocks of memory define using new and then some of which is returned to the heap without destroying the pointer. The pointer after delete is still defined.

testptr2.cpp

This program demonstrates two ways to initialize a place in memory created by the operator new.

testptr.cpp

Shows connection between operators and pointers.

varbaray.cpp

This program demonstrates that the number of elements of an array can be variable if the array is created with new.

voidptr.cpp

Shows pointers to void.

image from book

 // program_id       addreses.cpp // author            don voils // date written       11/23/2006 // // // program description    This program illustrates the use of //           the address operator. // #include<iostream> using namespace std; void main() {      char  resp;      short  s;      int  i;      long   l;      float  f;      double d;      long double ld;      // Check the output of these addresses. Notice the locations      // and compare these with the sizes of the respective instances.             //      cout << "The address of the short s is " << &s           << " and memory size is " <<sizeof(s)<< endl           << "The address of the int i is " << &i           << " and memory size is " <<sizeof(i)<< endl           << "The address of the long l is " << &l           << " and memory size is " <<sizeof(l)<< endl           << "The address of the float f is " << &f           << " and memory size is " <<sizeof(f)<< endl           << "The address of the double d is " << &d                << " and memory size is " <<sizeof(d) << endl           << "The address of the long double ld is " << &ld           << " and memory size is " <<sizeof(ld)<< endl << endl;      cout << "Continue? ";      cin >> resp;             cout << endl << endl; } // program_id         arrayptr.cpp // author           don voils // date written      11/23/2006 // // program description   This program illustrates the use of //                               using a pointer to control an array. // #include<iostream> using namespace std; void main() {      float gl[100];      float *ptr_gl;             int index;      ptr_gl = gl;      cout << "The pointer ptr_gl points to the "                  << endl << "array gl[] " << endl << endl;      for(index=0;index < 100; ++index)           *(ptr_gl+index) = (float)index;      cout << "The elements of the array gl[] are "                 << endl << "being initialized by using the "                 << endl << "pointer ptr_gl " << endl << endl;      cout << "The array gl[] has the following for elements"           << endl << endl;      for(index=0;index < 100; ++ index)           cout << gl[index] << endl;      float *ptr_gl1 = &gl[1];      cout << endl << endl << "The address stored in ptr_gl is " << ptr_gl;      cout << endl << endl << "The address stored in gl is " << gl;            cout << endl << endl << "The address stored in ptr_gl1 is " << ptr_gl1;      cout << endl << endl << "The address of gl[0] is " << &(gl[0]);      cout << endl << endl << "The address of gl[1] is " << &(gl[1]);            cout << endl << endl << "The size of gl[0] is " << sizeof(gl[0]);      cout << "Use Windows Calculator to see if the distance"                 << endl << "from gl[0] to gl[1]"                 << " is the same as the sizeof(gl[0]) above. " << endl << endl;      char resp;      cout<< endl << endl << "Continue? ";      cin >> resp;      cout << endl << endl; } // program_id            byPointer.cpp // author                don voils // date written         10/14/2006 // // // program description:    This program demonstrats passing by //                          pointer a variable into a //                          function thereby changing //                          the value of a local variable. // #include<iostream> using namespace std; void byPointer(long* r,long* t); void main(void) {      long  i = 734545,            j = 323423;      long *ptr1 = &i;      long *ptr2 = &j;      cout << "Before passing to function byPointer(): " << i           << " and " << j << endl << endl;      byPointer(ptr1,ptr2);      cout << "After passing to function byPointer(): " << i           << " and " << j << endl << endl; } void byPointer(long *r,long *t) {   cout << "Inside of function byPointer() before change:"        << *r << " and " << *t << endl << endl;   ++(*r);   ++(*t);   cout << "Inside of function byPointer() after change: "        << *r << " and " << *t << endl << endl; } // program_id                     date.cpp // author             don voils // date written        11/23/2006 // program description     This program seeks a //                 date and tells what day //                 of the week and month it is. // // Formula must be adjusted for dates before 11/24/1934. // # include<iostream> # include<conio.h> using namespace std; // FUNCTIONAL PROTOTYPES // long  month = 0L,       day = 0L,       year = 0L; void get_date(); void find_day_of_week_for(); long days_between(long,long,long); long days_since(long,long,long); long f(long,long); long g(long); void clear_screen(); bool incorrect_date(long,long,long); long days_in_month(long,long); bool is_leap_year(long); void main() {              clear_screen();              char catcher;      do      {         get_date();         find_day_of_week_for();         cout << endl << endl << "Another date? ";         catcher = getche();      }while(catcher=='y' || catcher=='Y');      cout << endl << endl; } void get_date() {   char dash;   do   {      cout << endl << endl << "FINDING THE DAY OF THE WEEK"           << endl << endl;        month = 0L;        day = 0L;        year = 0L;        cout << "What is the date? MM/DD/YY ";        cin >> month >> dash >> day >> dash >> year;        if(year < 10)      year = year + 2000;        else      if(year < 100)                year = year + 1900L;   }while(incorrect_date(month,day,year)); } void  find_day_of_week_for() {     int    number;     char *day_name[] = {"Saturday", "Sunday", "Monday", "Tuesday",                  "Wednesday", "Thursday", "Friday"};     char *month_name[] = {"","January", "February", "March", "April",             "May", "June", "July", "August",             "September", "October", "November", "December"};     number = int(days_between(month,day,year) % 7L);     cout << endl << endl << day_name[number] << " "               << month_name[int(month)] << " " << day << ", " << year; } long days_between(long month,long day,long year) {  long number = days_since(month,day,year) - days_since(11L,24L,1934L);  return(number); } long days_since(long month,long day,long year) {  long number = 1461L* f(month,year)/4L + 153L*g(month)/5L + day;  return(number); } long f(long month,long year) {  long number = (month<=2L) ? year - 1L : year;  return(number); } long g(long month) {  long number = (month<=2L) ? month + 13L : month + 1L;  return(number); } void clear_screen() {  for(int index=1;index<=25;++index)      cout << endl; } bool incorrect_date(long month,long day,long year) {  bool bad_date;  if (((month>=1L) && (month<=12L)) &&                   ((day>=1L) && (day<=days_in_month(month,year))))     bad_date = false;  else     bad_date = true;  return(bad_date); } long days_in_month(long month,long year) {  long upper_limit;  long days_in_month[] = {0L, 31L, 28L, 31L, 30L, 31L, 30L,               31L, 31L, 30L, 31L,30L, 31L};  if (month != 2L)       upper_limit = days_in_month[int(month)];  else       if (is_leap_year(year))             upper_limit = 29L;       else             upper_limit = days_in_month[int(month)];  return (upper_limit); } bool is_leap_year(long year) {  bool a_leap_year;  if (((year%4L == 0L) && (year%100L != 0L)) || (year%400L == 0L))        a_leap_year = true;  else        a_leap_year = false;  return(a_leap_year); } // program_id          delete.cpp // written_by          don l. voils // date_written       11/10/2006 // // // program description   Shows the use of pointers as output of functions. //                       Note that the operator delete is used only once. //                       even though the new operator is used twice to //                       create two different char arrays dynamically. // //                       As a variation uncomment the line below. // #include<iostream> using namespace std; char *getname(); void main() {       char * name;       name = getname();       cout << endl << endl << name                  << " is at " << (int *) name << endl;       // delete [] name;       name = getname();       cout << endl << endl                  << name << " is at "                  << (int *) name << endl;       delete [] name;       char resp;       cout << endl << endl << "Continue? ";       cin >> resp;       cout << endl << endl; } char * getname() {        char temp[80];        cout << endl << endl                   << "Enter last name: ";        cin >> temp;        char *pn = new char[strlen(temp)+1];        strcpy(pn, temp);               return pn; } // program_id            INDIRECT.CPP // written_by            don l. voils // date_written          11/10/2006 // // program description   Show the use of the indirection operator // #include<iostream> using namespace std; void main() {      char resp;      int   a_int = 5,           b_int;      int   *a_ptr = &a_int,           *b_ptr = &b_int;      *b_ptr = 15;      cout << "The value stored in a_int is " << *a_ptr << endl << endl                 << "The value store in b_int is " << b_int << endl;      cout << endl << endl << "Continue? ";      cin >> resp;      cout << endl << endl; } // program-id            MENUS.CPP // author                DON VOILS // date written          SEPTEMBER 21, 1988 // modified by        dlv // date(s) modified     12/3/2006 // // program description   THIS PROGRAM CONTAINS THE MENUS //                        FOR ALL MODULES OF THE ACCOUNTING //                        SYSTEM. FROM THESE MENUS THE USER //                        CAN SELECT WHICH OF THE ACCOUNTING //                        MODULES HE/SHE WANTS TO USE. // //                 One of the new modifications was the //                 creation of arrays of pointers to functions. //                 The individual menus were then changed so //                 that these arrays would call the individual //                 functions required by the menus. This was //                 done by using the ability of C++ to permit //                 late binding of function. Notice that in //                 each case the exact function to be used //                 on the menu choice is not determined //                 until the program is executed. This enables //                 the elimination of the switch. Late binding //                 causes the program to be larger but the //                 elimination of the switches makes it smaller. // #include<conio.h> #include<iostream> #include<iomanip> #include<string> #include<process.h> using namespace std; // FUNCTION PROTOTYPES // void expense_ldgr(); void sales_ldgr(); // Empty functions // void strtclnt(){}; void expenseout(){} void expenseedit(){} void expenseprt(){} void eomexpenses(){} void quit_expenses(){} void salesout(){}; void salesprt(){}; void salesedit(){}; void eomsales(){}; void quit_sales(){}; void pandl(){}; void eoy(){}; void quit() {      for(int loop_counter=0;loop_counter<=50;++loop_counter)                 cout << endl;      exit(1); } //   The following are arrays of pointers to functions which are //   used to make the individual menus work without the switch. // void (*menu1[])()={strtclnt, expense_ldgr, sales_ldgr, pandl, eoy, quit}; void (*menu2[])()={expenseout, expenseedit, expenseprt, eomexpenses, quit_expenses}; void (*menu3[])()={salesout, salesedit, salesprt, eomsales, quit_sales}; void main() {      char index;      do      {          for(int loop_counter=0;loop_counter<=50;++loop_counter)               cout << endl;          cout << "         Main Menu" << endl << endl << endl               << "   1.  Start New Client" << endl << endl               << "   2.  Expense Ledger Menu" << endl << endl               << "   3.  Sales Ledger Menu" << endl << endl               << "   4.  Print P&L" << endl << endl               << "   5.  End of Year Processing" << endl << endl               << "   6.  Exit" << endl << endl                            << "        Which? ";          cin.get(index).get(); //   This is an example of late binding. The compiler does not specify //   the location of the jump until the execution of the program. //           menu1[(index-'0')-1]();           for(loop_counter=0;loop_counter<=50;++loop_counter)                 cout << endl;      }while (1); } /*    program-id            EXPENSE_LDGR()      author                 DON VOILS      date written          SEPTEMBER 21, 1988      program description    THIS FUNCTION CONTAINS THE MENU               FOR THE EXPENSES. */ void expense_ldgr() {      int loop_counter;      char index;      /*   THIS MODULE HELPS THE USER TO SELECT WHICH           OF THE EXPENSE MODULES TO USE.      */      do      {           for(loop_counter=0;loop_counter<=50;++loop_counter)                    cout << endl;           cout << flush;           cout << "         Expense Ledger Menu" << endl << endl                << "     1. Enter Expenses" << endl << endl                << "     2. Change Expenses" << endl << endl                << "     3. Print Expense Ledger" << endl << endl                << "     4. End of Month Processing for Expenses"                << endl << endl                            << "     5. Return to Main Menu" << endl << endl                << "        Which? ";           cin.get(index).get();           menu2[(index-'0')-1]();           if (index=='5')                 break;      } while (1); } /*   program-id             SALES_LDGR()     author                DON VOILS     date written           SEPTEMBER 21, 1988     program description   THIS FUNCTION CONTAINS THE MENU              FOR THE SALES. */ void sales_ldgr() {           int  loop_counter;           char  index;      /*   THIS MODULE HELP THE USER TO SELECT WHICH           OF THE SALES MODULES TO USE.      */     do     {         for(loop_counter=0;loop_counter<=50;++loop_counter)                  cout << endl;         cout << flush;         cout << "        Sales Ledger Menu" << endl << endl            << "     1. Enter Sales" << endl << endl            << "     2. Change Sales" << endl << endl            << "     3. Print Sales" << endl << endl            << "     4. End of Month Processing for Sales"            << endl << endl            << "     5. Return to Main Menu" << endl << endl            << "         Which? ";         cin.get(index).get();         menu3[(index-'0')-1]();         if (index=='5')              break;    } while (1); } // program_id      nullptr.cpp // author           don voils // date written      11/23/2006 // // // program description   Shows the use of the NULL pointer. // #include<iostream> using namespace std; void main() {      float a_float;      float *ptr_float = NULL;      cout << "The address of a_float is "           << &a_float<< endl << endl;      cout << "The value stored in ptr_float is " << ptr_float                 << endl << endl;      if(!ptr_float)            cout << endl << "The pointer ptr_float is a NULL pointer."                              << endl << endl;      cout << "The address of a_float is now stored into ptr_float"                 << endl << endl;      ptr_float = &a_float;      if(ptr_float)            cout << endl << "The pointer ptr_float now contains the address "                              << ptr_float << endl << endl;      // The following would not compile.      // ptr_float = 50;      // In order for a non-zero integer to be stored into a pointer      // the integer must be typecast to a pointer of the appropriate      // type.      //      cout << "The integral value 50 is stored in ptr_float through typecasting."                 << endl << endl;            ptr_float = (float*) 50;            cout << "The value stored in ptr_float is "                 << ptr_float << endl << endl;      // While it is not possible to assign a non-zero into to a pointer      // it is possible to assign the value zero.      cout << "The integral value 0 is stored in ptr_float."                 << endl << endl;      ptr_float = 0;      cout << "The value stored in ptr_float is "                 << ptr_float << endl;      char resp;      cout << endl << endl << "Continue? ";      cin >> resp;      cout << endl << endl; } // program_id    pointerAddition.cpp // author               Don L. Voils // date written:       11/3/2006 // assignment: // // // program description   Shows pointers addition. // #include<iostream> using namespace std; void main() {      int *ptrInt,aInt;      double *ptrDouble,aDouble;      ptrInt = &aInt;      ptrDouble = &aDouble;      cout << "The address of aInt is " << &aInt           << " and ptrInt contains " << ptrInt << endl << endl           << "While size of aInt is " << sizeof(aInt) << endl           << " and ptrInt + 1 contains " << ptrInt+1           << endl << endl;      cout << "The address of aDouble is " << &aDouble           << " and ptrDouble contains " << ptrDouble << endl << endl           << "While size of aDouble is " << sizeof(aDouble) << endl                << " and ptrDouble + 1 contains " << ptrDouble+1           << endl << endl;      char resp;      cout << endl << endl << "Continue? ";      cin >> resp;      cout << endl << endl; } // program_id:           pointerconversion.cpp // author                  Don L. Voils // date written:          11/09/2006 // program description:   Shows how to initialize a pointer of a different type. //                         Shows that a pointer of one type may not work as a //                         pointer to different type. // #include<iostream> using namespace std; void main() {      float a_float = 5.67F;      int *ptr_int;      // The program will not compile with the      // statement below.      //ptr_int = &a_float;      // Using type conversiont, ptr_in may      // contain the address of the float: a_float      //      ptr_int = (int*) &a_float;      cout << "The address of a_float is " << &a_float << endl;      cout << "The value in a_float is " << a_float << endl << endl;      cout << "The address of a_float using the pointer ptr_int is "                 << ptr_int << endl;      cout << endl << "The value in a_float using the pointer ptr_int is "                 << *ptr_int << endl;      cout << endl << "The value in a_float using the pointer ptr_int " << endl                 << "with type conversion is " << float(*ptr_int)<< endl;      char resp;      cout << endl << endl << "Continue? ";      cin >> resp;      cout << endl << endl; } // program_id:      ptrinilz.cpp // author              Don L. Voils // date written:      11/09/2006 // // program description:   Shows how to initialize a pointer. // #include<iostream> using namespace std; void main() {      float a_float;      float *ptr_float;      ptr_float = &a_float;             cout << "The address of a_float is " << &a_float << endl;      cout << "The address of a_float using the pointer ptr_float is "                 << ptr_float << endl;      char resp;      cout << endl << endl << "Continue? ";      cin >> resp;      cout << endl << endl; } // program_id             ptrtofn.cpp // author            don voils // date written       11/23/2006 // // program description   This program illustrates the use of //          function pointers. // #include <iostream> using namespace std; int (*ptr)(float,char); int my_function(float f,char c) {      int  output;      cout << endl << endl << "The float is " << f << " and the char is "           << c << endl << endl;      cout << "What is the integer? ";      cin >> output;      cout << endl << endl;      return output; } void main() {      float f;      char c;      ptr = my_function;      cout << "This is a test of pointers to functions." << endl << endl;      cout << "What float do you want to use? ";      cin >> f;      cout << endl << endl << "What char do you want to use? ";      cin >> c;      cout << "Did you say the integer was " << ptr(f,c) << "?" << endl;      // Notice that the pointer is used in place of the function's name.      char resp;      cout << endl << endl << "Continue? ";      cin >> resp;      cout << endl << endl; } // program_id          relationalptr.cpp // author            don voils // date written       11/23/2006 // // program description    This program illustrates the use of //                                using a pointer with relational operators. // #include<iostream> using namespace std; void main() {   float gl[100];   float *ptr1,         *ptr2;   ptr1 = &gl[0];   ptr2 = &gl[5];   cout << "ptr1 points to the array element gl[0]. " << endl;   cout << "ptr2 points to the array element gl[5]. " << endl;  if(ptr1 < ptr2)     cout << endl << "The ptr1 points to an element in the array gl[]"          << endl << "before the element to which ptr2 points." << endl;  else     cout << endl << "The ptr2 points to an element in the array gl[]"          << endl << "before the the element to which ptr1 points." << endl;     char resp;     cout<< endl << endl << "Continue? ";     cin >> resp;     cout << endl << endl; } // program_id    renewptr.cpp // author          don voils // date written     11/23/2006 // // // program description    This program demonstrates the use of the //                         operators new and delete. It shows how //                         pointers are defined to point to blocks of //                         memory define using new and then some of //                         which is returned to the heap without //                  destroying the pointer. The pointer after //                         delete is still defined. #include<iostream> using namespace std; void main() {      int* ptr = new int;      *ptr = 5;      cout << "The integer to which ptr points has value " << *ptr << endl;      cout << "The location of the int to which ptr points is " << ptr << endl;      // This statement deletes the int to which ptr points but it      // does not destroy ptr. Notice below that ptr is used again      // to point to a different int created with new without defining      // it again. It still exists.      cout << endl << "The memory to which ptr points is deleted."                 << endl << endl;            delete ptr;      // This pointer was created to shift the memory for the second      // int to which ptr is to point. Without this pointer the address      // of the int to which ptr pointed turned up to be the same as      // before. This does not need to be true. I therefore defined this      // pointer to an int created with new to shift the available memory      // to a point where the second printout would give a different memory      // value.              cout << endl                   << "The pointer ptr2 receives the address of an int created dynamically."             << endl << endl;      int* ptr2 = new int;      cout << "The location of the int to which ptr2 points is "           << ptr2 << endl;      cout << endl                 << "The pointer ptr again receives the address of dynamic memory."                 << endl << "and it is initialized to 10." << endl << endl;      ptr = new int;      *ptr = 10;      cout << "The integer to which ptr points has value "           << *ptr << endl;      cout << "The location of the second int to which ptr points is "           << ptr << endl;      char resp;      cout << endl << endl << "Continue? ";      cin >> resp;      cout << endl << endl;            // The memory to which ptr and prt2 are pointing is now deleted      // although ptr and ptr2 are still available until they      // leave their scope i.e. the program ends.      //      delete ptr;      delete ptr2; } // program_id  testptr2.cpp // author               Don L. Voils // date written:        11/23/2006 // assignment: // // // program description     This program demonstrates two ways to //                          initialize a place in memory created //                          by the operator new. // #include<iostream> using namespace std; void main() {      int* ptr;      ptr = new int;      *ptr = 5;      int *ptr2 = new int(10);      cout << "The pointer ptr is pointing at " << *ptr << endl << endl;      cout << "The pointer ptr2 is pointing at " << *ptr2 << endl << endl;      delete ptr;      delete ptr2;      char resp;      cout << endl << endl << "Continue? ";      cin >> resp;      cout << endl << endl; } // program_id         testptr.cpp // author             Don L. Voils // date written:     11/09/2006 // // program description:  Shows connection between operators and pointers // #include<iostream> using namespace std; void main() {      char resp;      int a_int,          b_int;      int *a_ptr = &a_int,                 *b_ptr;      b_ptr = &b_int;      cout << "a_ptr and b_ptr are pointers to ints " << endl << endl;      cout << "The address stored in a_ptr is " << a_ptr << endl;      cout << "The address stored in a_ptr-5 is " << (a_ptr-5) << endl << endl;      cout << "5 times the size of a_int is " << 5 * sizeof(a_int) << endl << endl;      cout << "The address stored in b_ptr is " << b_ptr << endl;      cout << "The address stored in b_ptr+5 is " << (b_ptr+5) << endl << endl;      cout << "5 times the size of b_int is " << sizeof(b_int)*5 << endl;      cout << endl << endl <<"Using Window's calculator check the arithmetic"                 << " above to see if it is correct." << endl << endl;      cout << endl << endl << "Continue? ";      cin >> resp;      cout << endl << endl; } // program_id    varbaray.cpp // author                don voils // date written     12/5/2006 // // // program description   This program demonstrates that the number of //                        elements of an array can be variable if //                        the array is created with new. // #include<conio.h> #include<iostream> #include<iomanip> using namespace std; void main() {      char catcher;      int number;      int *ptr;      do      {           cout << endl << endl << "How large of an index do you want? ";           cin >> number;           ptr = new int[number];           if(ptr==NULL)                            exit(0);           cout << endl                             << "The addresses of the array elements:" << endl;           for(int index=0;index<number;++index)                cout << setw(3) << (index+1)                                        << " " << setw(10) << ptr + index                                        << endl;                         cout << endl << endl;           for(int index=0;index<number;++index)                ptr[index]=index;           cout << "The value stored in each element is: " << endl;           for(index=0;index<number;++index)                cout << setw(3) << (index+1) << " "                                        << setw(10) << (ptr[index]*5) << endl;           delete [] ptr;           cout << endl << "Do another one? ";           catcher = getche();           if(catcher == 'y' || catcher == 'Y')              cout << endl << endl                                << "Check to see if the addresses of the different"                                << " array elements are the same."                                << endl << endl;      }while(catcher == 'y' || catcher == 'Y');      cout << endl << endl; } // program_id  voidptr.cpp // author              Don L. Voils // date written:      11/3/2006 // // program description    Shows pointers to void. // #include<iostream> using namespace std; void main() {      float stuff = 34.56F,            *ptr_stuff1;      int *ptr_int;      double *ptr_double;      void *ptr_to_void;      ptr_to_void = &stuff;      ptr_stuff1 = (float*)ptr_to_void;              // The following would not compile nor would      // any modification of the following.      //      // cout << *ptr_to_void << endl << endl;      cout << "The value stored in stuff is " << stuff << endl << endl;      // However notice that the samething can be accomplished      // by use the typecasting to the pointer ptr_stuff1      // which is a pointer of the correct type.      //      cout << "The value to which ptr_to_void points "          << endl << " when the value has been transferred to a float pointer is "                << *ptr_stuff1 << endl << endl;      // Notice that while the following statement compiles,      // the output is not as would be expected because of the data type.      //      ptr_int = (int*) ptr_to_void;      ptr_double = (double*) ptr_to_void;      cout << "The value to which ptr_to_void points "                 << endl << "when the address has been transferred to an int pointer is "                 << *ptr_int << endl << endl           << "The value to which ptr_to_void points "                 << endl << "when the address has been tranferred to a double pointer is "                 << *ptr_double << endl << endl;      char resp;      cout << endl << endl << "Continue? ";      cin >> resp;      cout << endl << endl; } 




Intermediate Business Programming with C++
Intermediate Business Programming with C++
ISBN: 738453099
EAN: N/A
Year: 2007
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net