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

  1. // ex06006.cpp
  2. // Reference parameters eliminate pointer notation
  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 ptrfunc(bigone *p1);        // call by pointer
  13. void reffunc(bigone& p1);        // call by reference
  14.  
  15. main()
  16. {
  17.     ptrfunc(&bo);    // pass the address
  18.     reffunc(bo);    // pass the reference
  19. }
  20.  
  21. // ---- a pointer function
  22. void ptrfunc(bigone *p1)
  23. {
  24.     cout << '\n' << p1->serno;        // pointer notation
  25.     cout << '\n' << p1->text;
  26. }
  27.  
  28. // ---- a call by reference function
  29. void reffunc(bigone& p1)
  30. {
  31.     cout << '\n' << p1.serno;        // reference notation
  32.     cout << '\n' << p1.text;
  33. }
  34.