home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / tutorial / cpptutor / source / varargs.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-15  |  877 b   |  40 lines

  1.                                // Chapter 4 - Program 5 - VARARGS.CPP
  2. #include <iostream.h>
  3. #include <stdarg.h>
  4.  
  5.             // Declare a function with one required parameter
  6. void display_var(int number, ...);
  7.  
  8. void main()
  9. {
  10. int index = 5;
  11. int one = 1, two = 2;
  12.  
  13.    display_var(one, index);
  14.    display_var(3, index, index + two, index + one);
  15.    display_var(two, 7, 3);
  16. }
  17.  
  18.  
  19. void display_var(int number, ...)
  20. {
  21. va_list param_pt;
  22.  
  23.    va_start(param_pt, number);              // Call the setup macro
  24.  
  25.    cout << "The parameters are ";
  26.    for (int index = 0 ; index < number ; index++) 
  27.       cout << va_arg(param_pt, int) << " "; // Extract a parameter
  28.    cout << "\n";
  29.    va_end(param_pt);                        // Closing macro
  30. }
  31.  
  32.  
  33.  
  34.  
  35. // Result of Execution
  36. //
  37. // The parameters are 5
  38. // The parameters are 5 7 6
  39. // The parameters are 7 3
  40.