home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / C / ANSICPP.ZIP / EX06005.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-24  |  729 b   |  34 lines

  1. // ex06005.cpp
  2. // Reference parameters reduce overhead
  3. #include <iostream.h>
  4.  
  5. // ---------- a big structure
  6. struct bigone    {
  7.     int serno;
  8.     char text[1000];    // a lot of chars
  9. } bo = { 123, "This is a BIG structure"};
  10.  
  11. // -- two functions that have the structure as a parameter
  12. void slowfunc(bigone p1);        // call by value
  13. void fastfunc(bigone& p1);        // call by reference
  14.  
  15. main()
  16. {
  17.     slowfunc(bo);    // this will take a while
  18.     fastfunc(bo);    // this will be a snap
  19. }
  20.  
  21. // ---- a call-by-value function
  22. void slowfunc(bigone p1)
  23. {
  24.     cout << '\n' << p1.serno;
  25.     cout << '\n' << p1.text;
  26. }
  27.  
  28. // ---- a call by reference function
  29. void fastfunc(bigone& p1)
  30. {
  31.     cout << '\n' << p1.serno;
  32.     cout << '\n' << p1.text;
  33. }
  34.