topical media & game development

talk show tell print

basic-program-code-05-Ex5-11.c

? / basic-program-code-05-Ex5-11.c


  // Ex5_11.cpp
  include <iostream>
  using std::cout;
  using std::endl;
  
  double* treble(double);                   // Function prototype
  
  int main(void)
  {
     double num = 5.0;                      // Test value
     double* ptr = 0;                       // Pointer to returned value
  
     ptr = treble(num);
  
     cout << endl
          << "Three times num = " << 3.0*num;
  
     cout << endl
          << "Result = " << *ptr;           // Display 3*num
  
     cout << endl;
     return 0;
  }
  
  // Function to treble a value - mark 1
  double* treble(double data)
  {
     double result = 0.0;
  
     result = 3.0*data;
     return &result;
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.