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

  1. // ex06008.cpp
  2. // Returning a reference from a function
  3. #include <iostream.h>
  4. #include <stdlib.h>
  5.  
  6. // ---------- a date structure
  7. struct date {
  8.     int mo, da, yr;
  9. };
  10.  
  11. // -------- an array of dates
  12. date birthdays[] = {
  13.     {12, 17, 37},
  14.     {10, 31, 38},
  15.     { 6, 24, 40},
  16.     {11, 23, 42},
  17.     { 8,  5, 44},
  18. };
  19.  
  20. // ----- a function to retrieve a date
  21. date& getdate(int n)
  22. {
  23.     return birthdays[n-1];
  24. }
  25.  
  26. main(int argc, char *argv[])
  27. {
  28.     if (argc > 1)    {
  29.         date& bd = getdate(atoi(argv[1]));
  30.         cout << bd.mo << '/' << bd.da << '/' << bd.yr;
  31.     }
  32. }
  33.